Skip to content

Commit 6dbe37d

Browse files
authored
Explain throwing away return values
1 parent 86ab9f2 commit 6dbe37d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

3.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ So doing `x = print('hello')` set `x` to `None`. Here's what happened, explained
5959

6060
All functions need to return something. So does the print function, and that's why it returns `None`. Of course, `x = print('hello')` is useless compared to `print('hello')`, because the print function always returns `None` and we can do `x = None` without any printing.
6161

62+
Calling a function without assigning the return value to anything (e.g. `print('hello')`) simply throws away the return value. The interactive `>>>` prompt also echoes the return value back if it's not None:
63+
64+
```py
65+
>>> str(123)
66+
'123'
67+
>>>
68+
```
69+
6270
If you still have trouble understanding functions, feel free to come to a good Python IRC channel like [#python](https://kiwiirc.com/client/irc.freenode.net/#python), [##python-friendly](https://kiwiirc.com/client/irc.freenode.net/##python-friendly) or [##learnpython](https://kiwiirc.com/client/irc.freenode.net/##learnpython). There will be plenty of skilled people ready to help you. Just ask your question nicely and be patient.
6371

6472
You can also pass multiple parameters separated with commas. The print function will add spaces between them.

0 commit comments

Comments
 (0)