Search code examples
pythonprintingreturn

Why does this function return "None None" as well?


I've searched regarding this and came across list returning functions but I still don't understand it.

I'm trying to understand why Print function to another function returns the following :

Happy Birthday
Happy Birthday
None None

My Code:

def happy():
    print("Happy Birthday")

def main():
    print(happy(), happy())

main()

I know that function returns special object called :None. But I'm just trying to understand why it does so?


Solution

  • Every function always returns a value. If you don't explicitly return a value, and the function just gets all the way to the end, then it automatically returns None. Your function happy doesn't have any return statement, so at the end of the function, it automatically returns None.