Behind the python with the function name () and without () distinction.

Today the weather is not cold, fever. 9.18 alarm bells ringing, when people self-improvement.

python, sometimes encounter did not take () function is called after the name, this is why? Look at the following example.

. 1  DEF target ():    # define a function 
2      Print ( ' running ' )
 . 3  
. 4 of He = target () # calling function 
. 5  
. 6  
. 7  # outputs 
. 8         running

The example above is an example of our normal function call. Let's look at the following example.

. 1 DEF target ():    # define a function 
2      Print ( ' running ' )
 . 3 
. 4 of He = target # transfer function 
. 5 
. 6 
. 7 # outputs 
8

The above example, when we use the definition of the function of the target, not added (), so when we run, the result is no content.

 

This is because when you put a pair of small brackets on the back, this function will be executed; however, if you hold the brackets behind it, then it can be passed around, and can be assigned to other variables do not perform it.

Guess you like

Origin www.cnblogs.com/GouQ/p/11542196.html