-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_15.py
More file actions
57 lines (33 loc) · 898 Bytes
/
Task_15.py
File metadata and controls
57 lines (33 loc) · 898 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
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
def hello_world():
print("Hello, World!")
hello_world()
def greeting(first_name, last_name): # must use both arguments
print(f"Hello, {first_name} {last_name}!")
greeting("John", "Doe")
# There are 2 different kind of functions:
# 1. Functions that return a value
# 2. Functions that perform a task
def get_greeting(name):
return f"Hi {name}"
message = get_greeting("John")
print(message)
def decrement(number, by):
return number - by
# Long call
result = decrement(5, 2)
print(result)
# Short call
print(decrement(10, 4))
# Can also be written as
print(decrement(6, by=2))
# Default arguments
def decrement(number, by=1):
return number - by
print(decrement(10))
# Variabel number of arguments
def multiply(*numbers):
total = 1
for number in numbers:
total *= number
return total
print(multiply(1, 2, 3, 4, 5))