Answers for "python scope"

1

python scope

#Every one can use this varible
x = 9
def num_returner():
    return x
print(num_returner())

#--------------------------------------
x = 90
def private_var():
  num = 20
  return x + num
print(private_var())
#it will give an error because it is not the public variable on the function 
print(num)
Posted by: Guest on July-03-2021
3

python variable scope

a = 5

def f1():
  a = 2
  print(a)
  
print(a)   # Will print 5
f1()       # Will print 2
Posted by: Guest on May-20-2020
3

how does scope work in python

a = 5
b = 3

def f1():
  a = 2
  print(a)
  print(b)
  
print(a)   # Will print 5
f1()       # Will print 2 and 3
Posted by: Guest on July-11-2020

Python Answers by Framework

Browse Popular Code Answers by Language