February 2024
Beginner
352 pages
8h 16m
English
You’re now going to combine functions with what you know of variables from previous exercises. As you know, a variable gives a piece of data a name so you can use it in your program. If you have this code:
1 x = 10
then you created a piece of data named x that is equal to the number 10.
You also know that you can define (create) functions with parameters like this:
1 def print_one(arg1):
2 print(f"arg1: {arg1}")
The parameter arg1 is a variable similar to the x before, except it’s created for you when you call the function like this:
1 print_one("First!")
In Exercise 18, you learned how Python runs functions when you call them, but what happens if you did this:
1 y = "First!" ...Read now
Unlock full access