Add arguments info.
This commit is contained in:
parent
2994c7457b
commit
23329f8275
|
@ -167,6 +167,50 @@ or if it has parameters:
|
|||
greet_customer(1,ten)
|
||||
```
|
||||
|
||||
# Passing Arguments
|
||||
|
||||
```
|
||||
greet_customer(special_item):
|
||||
print(special_item)
|
||||
|
||||
greet_customer(beef)
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```
|
||||
beef
|
||||
```
|
||||
|
||||
## Using Keyword Arguments
|
||||
|
||||
Keyword arguments are nice for specifying a default but changeable argument.
|
||||
|
||||
Here's an example from P3, Ch2, ex7
|
||||
|
||||
```
|
||||
def create_spreadsheet(title, row_count = 1000):
|
||||
row_count = str(row_count)
|
||||
print("Creating a spreadsheet called " + title + " with " + row_count +" rows.")
|
||||
|
||||
create_spreadsheet("Applications", row_count = 10)
|
||||
```
|
||||
|
||||
```
|
||||
row_count = 1000
|
||||
```
|
||||
is the default
|
||||
|
||||
```
|
||||
row_count = 10
|
||||
```
|
||||
|
||||
is the passed argument and thus what is used for a result:
|
||||
|
||||
```
|
||||
Creating a spreadsheet called Applications with 10 rows.
|
||||
```
|
||||
|
||||
# Fun Projects
|
||||
|
||||
Design a shop using Ex7 and Ex9 as a frame:
|
||||
|
|
Loading…
Reference in New Issue