February 2024
Beginner
352 pages
8h 16m
English
You have been using the = character to name variables and set them to numbers or strings. We’re now going to blow your mind again by showing you how to use = and a new Python word return to set variables to be a value from a function. There will be one thing to pay close attention to, but first type this in:
Listing 21.1: ex21.py
1 def add(a, b):
2 print(f"ADDING {a} + {b}")
3 return a + b
4
5 def subtract(a, b):
6 print(f"SUBTRACTING {a} − {b}")
7 return a - b
8
9 def multiply(a, b):
10 print(f"MULTIPLYING {a} * {b}")
11 return a * b
12
13 def divide(a, b):
14 print(f"DIVIDING {a} / {b}")
15 return a / b
16
17
18 print("Let's do some math with just functions!") 19 20 ...Read now
Unlock full access