World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Internship Partner

In Association with
In collaboration with



Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
New to InsideAIML? Create an account
Employer? Create an account
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
Enter your email below and we will send a message to reset your password
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
589 Learners
Pallavi Dhotre
10 months ago
name=input("Enter your name:") #input() is built-in function
print(name) #print() is built-in function
x=10 #variable declared in a global namespace with the global scope of variable in python
def f1(): #function definition
print(x) #variable accessed inside the function
f1()
def f1(): #function definition
print("function start ")
def f2():
var = 10 # local scope of variable in python
print("local function, value of var:",var)
f2()
print("Try printing var from outer function: ",var)
f1()
function start
local function, value of var: 10
Traceback (most recent call last):
File "<string>", line 10, in <module>
File "<string>", line 9, in f1
NameError: name 'var' is not defined
x='I am Global' #global namespace and global scope of variable in python
def f1(): #function definition
y='I am Local' # local namespace and local scope of variable in python
print(x) #accessing global namespace from local namespace
print(y) #accessing local namespace, we use
f1() #function calling
print('I am Built-in') # print() is a built-in namespace
I am Global
I am Local
I am Built-in
def fun1():
x = "local" # local scope
print(x)
fun1()
local
x = "Global"
def fun1():
print(x)
fun1()
print(x)
Global
Global
def fun1():
x = "outer Function"
def fun2():
print(x)
fun2()
fun1()
outer Function
x='I am a global variable I have global scope' #global namespace this has a global scope in python
def f1(): #function definition
y='I am a Local variable I have local scope' # local namespace
print(x) #accessing global namespace from local namespace
print(y) #accessing local namespace
f1() #function calling
print('I am a Built-in function I have built-in scope') # print() is a built-in namespace
I am a Global variable I have global scope
I am a Local variable I have local scope
I am a Built-in function I have built-in scope