Skip to content

Commit 931f5a7

Browse files
committed
better variable names, some other stuff
1 parent 9f63f35 commit 931f5a7

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

using-functions.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,21 @@ text appears on the screen right away when we run `print(something)`.
5353

5454
## Return values
5555

56-
If we do `x = print('hello')`, what is x?
56+
If we do `thingy = print('hello')`, what does the `thingy` variable end
57+
up [pointing to](variables.md)?
5758

5859
```py
59-
>>> x = print('hello')
60+
>>> thingy = print('hello')
6061
hello
61-
>>> print(x) # x is now None
62+
>>> print(thingy) # thingy is now None
6263
None
6364
>>>
6465
```
6566

66-
So doing `x = print('hello')` set x to None. Here's what happened,
67-
explained in more detail:
67+
So doing `thingy = print('hello')` set `thingy` to None. Here's what
68+
happened, explained in more detail:
6869

69-
- In `x = print('hello')`, the right side is processed first.
70+
- In `thingy = print('hello')`, the right side is processed first.
7071
- `print('hello')` calls the print function with the argument
7172
`'hello'`.
7273
- The function runs. It shows the word hello.
@@ -75,46 +76,46 @@ explained in more detail:
7576
anything else.
7677
- Now the right side has been processed. `print('hello')` returned
7778
None, so we can imagine we have None instead of `print('hello')`
78-
there, and the assignment now looks like `x = None`.
79-
- x is now None.
79+
there, and the assignment now looks like `thingy = None`.
80+
- `thingy` is now None.
8081

8182
Now we understand what a return value is. When we call the function,
8283
Python "replaces" `function(args)` with whatever the function returns.
8384

8485
Calling a function without assigning the return value to anything (e.g.
85-
`print('hello')` instead of `x = print('hello')`) simply throws away
86+
`print('hello')` instead of `thingy = print('hello')`) simply throws away
8687
the return value. The interactive `>>>` prompt doesn't echo the return
8788
value back because it's None.
8889

89-
Of course, `x = print('hello')` is useless compared to `print('hello')`
90-
because the print function always returns None and we can do `x = None`
90+
Of course, `thingy = print('hello')` is useless compared to `print('hello')`
91+
because the print function always returns None and we can do `thingy = None`
9192
without any printing.
9293

9394
Not all functions return None. The input function can be used for
9495
getting a string from the user.
9596

9697
```py
97-
>>> x = input("Enter something:")
98+
>>> stuff = input("Enter something:")
9899
Enter something:hello
99-
>>> x
100+
>>> stuff
100101
'hello'
101102
>>>
102103
```
103104

104105
`input("Enter something:")` showed the text `Enter something:` on the
105106
screen and waited for me to type something. I typed hello and pressed
106107
Enter. Then input returned the hello I typed as a string and it was
107-
assigned to x.
108+
assigned to `stuff`.
108109

109110
Usually we want to add a space after the `:`, like this:
110111

111112
```py
112-
>>> x = input("Enter something: ") # now there's space between : and where i type
113+
>>> stuff = input("Enter something: ") # now there's space between : and where i type
113114
Enter something: hello
114115
>>>
115116
```
116117

117-
## More about print
118+
## Handy things about print
118119

119120
We can also print an empty line by calling print without any
120121
arguments.
@@ -135,7 +136,7 @@ world
135136
>>>
136137
```
137138

138-
If we want to print a backslash, we need to **escape** it by typing
139+
If we want to print a real backslash, we need to **escape** it by typing
139140
two backslashes.
140141

141142
[comment]: # (For some reason, GitHub's syntax highlighting doesn't)
@@ -168,8 +169,9 @@ Unlike with `+`, the arguments don't need to be strings.
168169
`function(1, 2, 3)` calls a function with 1, 2 and 3 as arguments.
169170
- When a function is called, it does something and returns something.
170171
- `function(stuff)` is "replaced" with the return value in the code
171-
that called it. For example, `x = function()` calls a function, and
172-
then does `x = the_return_value` and the return value ends up in x.
172+
that called it. For example, `stuff = function()` calls a function,
173+
and then does `stuff = the_return_value` and the return value ends
174+
up in x.
173175
- Python comes with `print` and `input`. They are built-in functions.
174176

175177
***

0 commit comments

Comments
 (0)