June 2017
Beginner
320 pages
7h 37m
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:
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 * b1213 def divide(a, b):14 print(f"DIVIDING {a} / {b}")15 return a / b16 17
Read now
Unlock full access