Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80243

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

Newsgroups comp.lang.python
Date 2014-11-04 19:15 -0800
Message-ID <79948f2a-df75-4161-8b78-450a0ba9f16b@googlegroups.com> (permalink)
Subject What is the difference between these two? (Assigning functions to variables)
From Max Nathaniel Ho <maxhowl86@gmail.com>

Show all headers | View raw


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!

Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

What is the difference between these two? (Assigning functions to variables) Max Nathaniel Ho <maxhowl86@gmail.com> - 2014-11-04 19:15 -0800
  Re: What is the difference between these two? (Assigning functions to variables) Max Nathaniel Ho <maxhowl86@gmail.com> - 2014-11-04 19:17 -0800
    Re: What is the difference between these two? (Assigning functions to variables) Cameron Simpson <cs@zip.com.au> - 2014-11-05 16:59 +1100
      Re: What is the difference between these two? (Assigning functions to variables) Max Nathaniel Ho <maxhowl86@gmail.com> - 2014-11-04 23:33 -0800

csiph-web