0
Check code below for difference between print and return↓
7 Respuestas
+ 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.