Learn Before
Code

Code examples for Scope

x = 5 #x is in Global scope def myfunc(): y = 12 # y is in Local scope print(y) # this statement prints 12 print(x) # this statement prints 5 print(x) # this statement prints 5 print(y) # this statement gives an error because variable # y is in local scope and can only be accessed # from inside the function

0

2

Updated 2021-02-05

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science