What is the difference between these two? (Assigning functions to variables)

Max Nathaniel Ho maxhowl86 at gmail.com
Wed Nov 5 04:15:30 CET 2014

Example 1

def compose_greet_func():
    def get_message():
        return "Hello there!"

    return get_message

greet = compose_greet_func()
print greet()

Example 2 

def greet(name):
    return "hello "+name

greet_someone = greet
print greet_someone("John"

In Example 1, the function compoe_greet_func is assigned to the variable greet, and () is included at the end of the function.

However, in Example 2, the function greet is assigned to the variable greet_someone but () is excluded at the end of the function.

Does the () matter when assigning functions to variables? 

Thank you!

More information about the Python-list mailing list