-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path008_functions.py
More file actions
32 lines (25 loc) · 782 Bytes
/
008_functions.py
File metadata and controls
32 lines (25 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
def add(a: int, b: int) -> int:
"""Helper function (defined outside)"""
return a + b
def greet(name: str, age: int = 25) -> None:
"""Default parameters"""
print(f"Hello {name}, you are {age} years old.")
def functions():
"""05_functions.py - Functions, args, *args, **kwargs"""
greet("Bob")
greet("Alice", 32)
print(f"Sum: {add(5, 7)}")
# Variable arguments
def sum_all(*args):
return sum(args)
print(f"Sum of many numbers: {sum_all(1, 2, 3, 4, 5)}")
# Keyword arguments
def print_info(**kwargs):
for key, value in kwargs.items():
print(f" {key}: {value}")
print_info(name="Emma", age=27, city="NYC")
def main():
functions()
if __name__ == '__main__':
main()