Python Forum
Function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Function (/thread-7985.html)



Function - AmanTripathi - Feb-01-2018

Code:
def h():
    print('hey')
print(h(),'hello')
Output:
Output:
hey None hello
Please someone explain me the output. I am a beginner and have just started learning python.


RE: Function - buran - Feb-01-2018

every function returns something. if it does not return anything explicitly, it returns None. That is the case with your function h - it does not return anything explicitly, so it return None
on line 3, it first call function h, it prints hey - that is the first line of the output and returns None, so your print function actually gets a 2 element tuple - None, 'hello' and prints it (that is the second line of the output)


RE: Function - AmanTripathi - Feb-02-2018

(Feb-01-2018, 07:11 PM)buran Wrote: every function returns something. if it does not return anything explicitly, it returns None. That is the case with your function h - it does not return anything explicitly, so it return None
on line 3, it first call function h, it prints hey - that is the first line of the output and returns None, so your print function actually gets a 2 element tuple - None, 'hello' and prints it (that is the second line of the output)

Thank you :) Also, will take care of the format in future. :)