Output: Print
Challenge 2-1: Functions
We know that calling the print() function displays something to the screen. Here we use print() in our function:
>>> def double_number(number):
print(number * 2)
Then call the function, passing it the number 12:
>>> double_number(12)
24
Let's call the function again, this time assigning it to the variable new_number:
>>> new_number = double(12)
24
But what happens here?
>>> new_number
We’ve worked with print() in a few of our examples, so we know what it does - we give it a value and it shows that value in our interpreter. But all it does is display that value - the value isn’t saved.
Let’s look at our example. We've defined a function called double_number that takes a number and multiplies it by two. When we call that function and assign its value to the variable new_number, it will print the number 24.
But the next time you enter new_number, it doesn’t have the value 24 anymore. The value hasn’t been saved.