[Python] python: return, return None, and no return at all -- is there any difference?

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    Consider these three functions:

    def my_func1():
    print "Hello World"
    return None

    def my_func2():
    print "Hello World"
    return

    def my_func3():
    print "Hello World"


    They all appear to return None. Are there any differences between how the returned value of these functions behave? Are there any reasons to prefer one versus the other?


    See also: is it possible to not return anything from a function in python?

    Continue reading...

Compartilhe esta Página