0
Check code below for difference between print and returnâ
7 Answers
+ 2
# make return function
def isEven(num):
# only returns True if even
return num%2 == 0
# make a void function
def isEvenVoid(num):
# prints out value instead
print(num%2 == 0)
# call the functions
print( IsEven(4) )
# no typing print statement
IsEvenVoid(4)
# with print statement
print( IsEvenVoid(4) )
Output:
True
True
True
None
It outputs None and True because the IsEvenVoid() function doesnt return a value...only prints it out when it is called
+ 1
Return is most often used to store output of a function in a variable, or as a parameter to another function
Print functions are void and do not return any value. The print function only prints stuff to the screen
+ 1
Ill explain this using python
+ 1
~ swim ~ I like that analogyđ Ill use it next time I have to explain itđđŒ
+ 1
return doesn't output anything, it just transports a value from one place to another.