Added another example to defining-functions article (#28449)
Added an example to help show how to define and call functions in a simple and easy to understand manner.
This commit is contained in:
committed by
Randell Dawson
parent
0a72391002
commit
43f2e6223f
@ -48,3 +48,24 @@ We can define a function inside another function!
|
||||
|
||||
If a function is defined inside another function, the inner function can only be called inside the function in which it was defined.
|
||||
|
||||
### Another Example
|
||||
|
||||
```python
|
||||
>>> def print_letters_blank(name): # define the function, give a argument if necessary
|
||||
|
||||
# loop to print out each letter in the name
|
||||
for letter in name:
|
||||
print(letter)
|
||||
|
||||
>>> print_letters_blank("John") # call the function
|
||||
>>> print_letters_blank("Sarah") # call the function again, but with a different argument
|
||||
J
|
||||
o
|
||||
h
|
||||
n
|
||||
S
|
||||
a
|
||||
r
|
||||
a
|
||||
h
|
||||
```
|
||||
|
Reference in New Issue
Block a user