mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Update python.html.markdown
This commit is contained in:
parent
610676c76e
commit
25e194aa0f
@ -613,15 +613,17 @@ y = 2
|
|||||||
x, y = swap(x, y) # => x = 2, y = 1
|
x, y = swap(x, y) # => x = 2, y = 1
|
||||||
# (x, y) = swap(x,y) # Again parenthesis have been excluded but can be included.
|
# (x, y) = swap(x,y) # Again parenthesis have been excluded but can be included.
|
||||||
|
|
||||||
# Function Scope
|
# global scope
|
||||||
x = 5
|
x = 5
|
||||||
|
|
||||||
def set_x(num):
|
def set_x(num):
|
||||||
# Local var x not the same as global variable x
|
# local scope begins here
|
||||||
|
# local var x not the same as global var x
|
||||||
x = num # => 43
|
x = num # => 43
|
||||||
print(x) # => 43
|
print(x) # => 43
|
||||||
|
|
||||||
def set_global_x(num):
|
def set_global_x(num):
|
||||||
|
# global indicates that particular var lives in the global scope
|
||||||
global x
|
global x
|
||||||
print(x) # => 5
|
print(x) # => 5
|
||||||
x = num # global var x is now set to 6
|
x = num # global var x is now set to 6
|
||||||
|
Loading…
Reference in New Issue
Block a user