Skip to content

Commit 013be0d

Browse files
committed
explaining stuff better
1 parent 6820579 commit 013be0d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

defining-functions.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ This function can be called in two ways:
248248
arguments, because each argument has a name and it's easy to see
249249
which argument is which.
250250

251-
Also note that there are no spaces around the `=` sign. That's
252-
because we are not assigning to a variable, we are giving the
253-
function a keyword argument and it can do whatever it wants with
254-
it.
251+
Also note that there are no spaces around the `=` sign. This is
252+
just a small style detail that Python programmers like to do
253+
because `message = "hi"` and `some_function(message="hi")` do two
254+
completely different things.
255255

256256
Personally, I would use this function with a positional argument. It
257257
only takes one argument, so I don't need to worry about which argument
@@ -351,21 +351,33 @@ need to:
351351

352352
## Output
353353

354-
The built-in input function returns a value. Can our function return a
355-
value also?
354+
The built-in input function [returns a value](https://github.com/Akuli/python-tutorial/blob/master/using-functions.md#return-values).
355+
Can our function return a value also?
356356

357357
```py
358358
>>> def times_two(x):
359359
... return x * 2
360360
...
361361
>>> times_two(3)
362362
6
363-
>>> times_two("hello")
364-
'hellohello'
363+
>>> times_two(5)
364+
10
365365
>>>
366366
```
367367

368-
Yes, it can.
368+
Yes, it can. Now typing `times_two(3)` to the prompt does the same
369+
thing as typing `6` to the prompt.
370+
371+
We can call the `times_two` function and use the result however we
372+
want, just like we can use built-in functions:
373+
374+
```py
375+
>>> times_two(2) + times_two(3) # calculate 4 + 6
376+
10
377+
>>> print('2 * 5 is', times_two(5))
378+
2 * 5 is 10
379+
>>>
380+
```
369381

370382
Note that **returning from a function ends it immediately**.
371383

0 commit comments

Comments
 (0)