+ 2

Def Function

1)def cube(num): return num*num*num cube(3) Output: No output. 2)def cube(num): print(num*num*num) print(cube(3)) Output: 27 None Can somebody pls explain why the output is like that? Thx

24th Jun 2020, 4:14 AM
M.O.HONOR
M.O.HONOR - avatar
5 Answers
+ 3
Hey M.O.HONOR In Your Query, Case 1: You returning the value but you won’t assigned any variable to hold that value or even you won’t used print() function so that the return value can be consoled to your screen whereas in Case2: the return value can be consoled to screen because you used print() function which will show the value of your function as ouput to the console screen.
24th Jun 2020, 4:19 AM
Rahul Saxena
Rahul Saxena - avatar
+ 4
M.O.HONOR print function is used to display output on the screen... In 1st case you only pass the argument and return the value and doesn't use print function to display it In 2nd case you use print function that is visible in output....
24th Jun 2020, 4:16 AM
Indira
Indira - avatar
+ 2
Thank you Indira and Ryan
24th Jun 2020, 4:29 AM
M.O.HONOR
M.O.HONOR - avatar
+ 1
Glad To Help 😊
24th Jun 2020, 4:30 AM
Rahul Saxena
Rahul Saxena - avatar