Interpretation of python
Explain how python is interpreted?
- The source code of a Python application is immediately executed.
- Code is necessary for every execution of a Python application.
Python translates the programmer's source code into intermediate language, which is then translated once more into the native language or machine language that is executed. Python is therefore an interpretive language.
- The interpreter processes it in real time.
- The software does not need to be compiled before running.
- It is comparable to PHP and PERL.
- Python is also interactive, allowing programmers to directly prompt and communicate with the interpreter.
What Python rules apply to local and global variables?
A variable is implicitly global if it is declared outside of a function. It is local if a variable receives a new value inside of a function. It must be specifically defined as global if we wish to make it universal. In the function, variables are implicitly global. The difference is further explained by the following snippet of code.
#!/usr/bin/python
# Filename: variable_localglobal.py
def fun1(a):
print 'a:', a
a= 33;
print 'local a: ', a
a = 100
fun1(a)
print 'a outside fun1:', a
def fun2():
global b
print 'b: ', b
b = 33
print 'global b:', b
b =100
fun2()
print 'b outside fun2', b
-------------------------------------------------------
Output
$ python variable_localglobal.py
a: 100
local a: 33
a outside fun1: 100
b :100
global b: 33
b outside fun2: 33
# Filename: variable_localglobal.py
def fun1(a):
print 'a:', a
a= 33;
print 'local a: ', a
a = 100
fun1(a)
print 'a outside fun1:', a
def fun2():
global b
print 'b: ', b
b = 33
print 'global b:', b
b =100
fun2()
print 'b outside fun2', b
-------------------------------------------------------
Output
$ python variable_localglobal.py
a: 100
local a: 33
a outside fun1: 100
b :100
global b: 33
b outside fun2: 33
Comments
Post a Comment