Skip to content

Commit

Permalink
Merge pull request #9 from phihag/patch-9
Browse files Browse the repository at this point in the history
global&return: PEP8
  • Loading branch information
yasoob committed Aug 17, 2015
2 parents a1259b1 + 6e8b5c7 commit cca86ad
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions global_&_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ Global & Return
---------------

You might have encountered some functions written in python which have a
return keyword in the end of the function. Do you know what it does ? It
return keyword in the end of the function. Do you know what it does? It
is similar to return in other languages. Lets examine this little
function:

.. code:: python
def add(value1,value2):
def add(value1, value2):
return value1 + value2
result = add(3,5)
result = add(3, 5)
print(result)
# Output: 8
Expand Down Expand Up @@ -41,10 +41,10 @@ scope of the function as well. Let me demonstrate it with an example :
.. code:: python
# first without the global variable
def add(value1,value2):
def add(value1, value2):
result = value1 + value2
add(2,4)
add(2, 4)
print(result)
# Oh crap we encountered an exception. Why is it so ?
Expand All @@ -59,15 +59,16 @@ scope of the function as well. Let me demonstrate it with an example :
# Now lets run the same code but after making the result
# variable global
def add(value1,value2):
def add(value1, value2):
global result
result = value1 + value2
add(2,4)
add(2 ,4)
result
6
So hopefully there are no errors in the second run as expected. In
practical programming you should try to stay away from ``global``
keyword as it only makes life difficult by introducing unwated variables
to the global scope.

0 comments on commit cca86ad

Please sign in to comment.