-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
66 lines (35 loc) · 1.09 KB
/
functions.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def greet():
print("Hello, welcome to Python!")
greet()
# Challenge 1: Create a function that takes a name as an argument and prints "Hello, [name]":
def greet(name):
print(f"Hello, {name}! Welcome to Python!")
return name
def greet(name="Guest"):
print(f"Hello, {name}! Welcome to Python!")
greet("Alice") # Output: Hello, Alice! Welcome to Python!
greet() # Output: Hello, Guest! Welcome to Python!
def print_numbers(*args):
for number in args:
print(number)
print_numbers(1, 2, 3, 4) # Output: 1 2 3 4
def print_key_values(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
print_key_values(a=1, b=2, c=3) # Output: a: 1 b: 2 c: 3
def outer_function(text):
def inner_function():
print(text)
inner_function()
outer_function("Hello from inner function")
def add(a, b):
"""
Adds two numbers.
Parameters:
a (int): The first number.
b (int): The second number.
Returns:
int: The sum of a and b.
"""
return a + b
print(len("Hello")) # len is a built-in function