From c86c82f4b5081f542ea580088b53574c09b6688c Mon Sep 17 00:00:00 2001 From: "Stanislav (Stanley) Modrak" <44023416+smith558@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:36:17 +0100 Subject: Update python.html.markdown --- python.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 4aeb93f4..2f91d452 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -419,7 +419,7 @@ for animal in ["dog", "cat", "mouse"]: """ "range(number)" returns an iterable of numbers -from zero to the given number +from zero up to (but excluding) the given number prints: 0 1 @@ -628,6 +628,12 @@ def set_global_x(num): set_x(43) set_global_x(6) +""" +prints: + 43 + 5 + 6 +""" # Python has first class functions -- cgit v1.2.3 From 610676c76efa7532975cfcc8dc5b8b69cdce1a84 Mon Sep 17 00:00:00 2001 From: "Stanislav (Stanley) Modrak" <44023416+smith558@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:37:42 +0100 Subject: Update python.html.markdown --- python.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 2f91d452..22827963 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -9,6 +9,7 @@ contributors: - ["Rommel Martinez", "https://ebzzry.io"] - ["Roberto Fernandez Diaz", "https://github.com/robertofd1995"] - ["caminsha", "https://github.com/caminsha"] + - ["Stanislav Modrak", "https://stanislav.gq"] filename: learnpython.py --- -- cgit v1.2.3 From 25e194aa0fe8cb82ca8f68c14993d31bf55bf034 Mon Sep 17 00:00:00 2001 From: "Stanislav (Stanley) Modrak" <44023416+smith558@users.noreply.github.com> Date: Wed, 26 Oct 2022 19:30:44 +0100 Subject: Update python.html.markdown --- python.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 22827963..687529b5 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -613,15 +613,17 @@ y = 2 x, y = swap(x, y) # => x = 2, y = 1 # (x, y) = swap(x,y) # Again parenthesis have been excluded but can be included. -# Function Scope +# global scope x = 5 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 print(x) # => 43 def set_global_x(num): + # global indicates that particular var lives in the global scope global x print(x) # => 5 x = num # global var x is now set to 6 -- cgit v1.2.3