Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function
#1
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.
Reply
#2
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)
Reply
#3
(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. :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020