0

Python "return"

The tutorial states that we can return "a value that can be used later". What exactly does "can be used later" mean? When and how can I use the value? Are the variables not already defined and populated?

5th Dec 2019, 9:58 PM
Objective Christian
Objective Christian - avatar
3 Respuestas
+ 2
Objective Christian example: a function or operator body returns the current date. You yourself expect to return something from the function and assign this value to the variable. otherwise, why call a function that returns something ?
5th Dec 2019, 10:05 PM
Petr
0
By "using it later", it would mean that the returned value can be stored in a variable. example: def sum(num1, num2) # function_name(argument1, argument2, etc...) return num1 + num2 # simple operation # Stores value of sum, when called with 1 and 2 as parameters -> sum(1, 2) OnePlusTwo = sum(1, 2) # Uses & prints out the value returned by sum(1, 2) print("1+2 = ", OnePlusTwo)
20th Dec 2019, 6:04 AM
SoundInfinity
SoundInfinity - avatar