0

Check code below for difference between print and return↓

https://code.sololearn.com/c1b1IXw5v5hR/?ref=app

5th Aug 2019, 9:05 AM
The unknown 321
The unknown 321 - avatar
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
5th Aug 2019, 10:08 AM
Trigger
Trigger - avatar
+ 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
5th Aug 2019, 10:04 AM
Trigger
Trigger - avatar
+ 1
Ill explain this using python
5th Aug 2019, 10:04 AM
Trigger
Trigger - avatar
+ 1
~ swim ~ I like that analogy😁 Ill use it next time I have to explain itđŸ‘đŸŒ
5th Aug 2019, 10:10 AM
Trigger
Trigger - avatar
+ 1
return doesn't output anything, it just transports a value from one place to another.
5th Aug 2019, 12:07 PM
HonFu
HonFu - avatar