Skip to content

Commit 257709f

Browse files
authored
Global and Return edits (#232)
* replaced "&" with "and" in article heading * fixed minor typos
1 parent 9b6262e commit 257709f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

global_&_return.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Global & Return
1+
Global and Return
22
---------------
33

4-
You might have encountered some functions written in python which have a
4+
You might have encountered some functions written in Python which have a
55
``return`` keyword in the end of the function. Do you know what it does? It
6-
is similar to return in other languages. Lets examine this little
6+
is similar to return in other languages. Let's examine this little
77
function:
88

99
.. code:: python
@@ -15,7 +15,7 @@ function:
1515
print(result)
1616
# Output: 8
1717
18-
The function above takes two values as input and then output their
18+
The function above takes two values as input and then outputs their
1919
addition. We could have also done:
2020

2121
.. code:: python
@@ -28,11 +28,11 @@ addition. We could have also done:
2828
print(result)
2929
# Output: 8
3030
31-
So first lets talk about the first bit of code which involves the
31+
So first let's talk about the first bit of code which involves the
3232
``return`` keyword. What that function is doing is that it is assigning
3333
the value to the variable which is calling that function which in our
34-
case is ``result``. In most cases and you won't need to use the
35-
``global`` keyword. However lets examine the other bit of code as well
34+
case is ``result``. In most cases you won't need to use the
35+
``global`` keyword. However, let's examine the other bit of code as well
3636
which includes the ``global`` keyword. So what that function is doing is
3737
that it is making a global variable ``result``. What does global mean
3838
here? Global variable means that we can access that variable outside the
@@ -125,11 +125,11 @@ Or by more common convention:
125125
print(profile_age)
126126
# Output: 30
127127
128-
Keep in mind that even in the above example we are returning a tuple (despite the lack of paranthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple <https://docs.python.org/3/library/collections.html#collections.namedtuple>`_. Here is an example:
128+
Keep in mind that even in the above example we are returning a tuple (despite the lack of parenthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple <https://docs.python.org/3/library/collections.html#collections.namedtuple>`_. Here is an example:
129129

130130
.. code:: python
131131
132-
from collections import namedtuple
132+
from collections import namedtuple
133133
def profile():
134134
Person = namedtuple('Person', 'name age')
135135
return Person(name="Danny", age=31)
@@ -157,4 +157,4 @@ Keep in mind that even in the above example we are returning a tuple (despite th
157157
print(age)
158158
#31
159159
160-
This is a better way to do it along with returning ``lists`` and ``dicts``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them.
160+
This is a better way to do it, along with returning ``list`` and ``dict``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them.

0 commit comments

Comments
 (0)