@@ -242,58 +242,12 @@ def print_box(message):
242
242
print (' *' * len (message))
243
243
```
244
244
245
- # # Output
246
-
247
- The built- in input function returns a value. Can our function return a
248
- value also?
249
-
250
- ```py
251
- >> > def times_two (x ):
252
- ... return x * 2
253
- ...
254
- >> > times_two(3 )
255
- 6
256
- >> > times_two(" hello" )
257
- ' hellohello'
258
- >> >
259
- ```
260
-
261
- Yes, it can.
262
-
263
- Note that ** returning from a function ends it immediately** .
264
-
265
- ``` py
266
- >> > def return_before_print ():
267
- ... return None
268
- ... print (" This never gets printed." )
269
- ...
270
- >> > return_before_print()
271
- >> >
272
- ```
273
-
274
- If we don't have any return statements or we have a return statement
275
- that doesn't specify what to return, our function will return None.
276
-
277
- ``` py
278
- >> > def return_none_1 ():
279
- ... pass
280
- ...
281
- >> > def return_none_2 ():
282
- ... return
283
- ...
284
- >> > print (return_none_1())
285
- None
286
- >> > print (return_none_2())
287
- None
288
- >> >
289
- ```
290
-
291
245
# # Default values
292
246
293
247
What if we want to print different characters instead of always
294
248
printing stars?
295
249
296
- We could change our print_box function to take two arguments:
250
+ We could change our ` print_box` function to take two arguments:
297
251
298
252
```py
299
253
def print_box(message, character):
@@ -371,6 +325,52 @@ need to:
371
325
this, because if you accidentally call a function like this you
372
326
will get an error message.
373
327
328
+ # # Output
329
+
330
+ The built- in input function returns a value. Can our function return a
331
+ value also?
332
+
333
+ ```py
334
+ >> > def times_two (x ):
335
+ ... return x * 2
336
+ ...
337
+ >> > times_two(3 )
338
+ 6
339
+ >> > times_two(" hello" )
340
+ ' hellohello'
341
+ >> >
342
+ ```
343
+
344
+ Yes, it can.
345
+
346
+ Note that ** returning from a function ends it immediately** .
347
+
348
+ ``` py
349
+ >> > def return_before_print ():
350
+ ... return None
351
+ ... print (" This never gets printed." )
352
+ ...
353
+ >> > return_before_print()
354
+ >> >
355
+ ```
356
+
357
+ If we don't have any return statements or we have a return statement
358
+ that doesn't specify what to return, our function will return None.
359
+
360
+ ``` py
361
+ >> > def return_none_1 ():
362
+ ... pass
363
+ ...
364
+ >> > def return_none_2 ():
365
+ ... return
366
+ ...
367
+ >> > print (return_none_1())
368
+ None
369
+ >> > print (return_none_2())
370
+ None
371
+ >> >
372
+ ```
373
+
374
374
## Exercises
375
375
376
376
** There is a lot to learn with functions, and I don't expect you to
0 commit comments