[python] Value of function object (?)

Summary

In python, the value of a function object (I don't know ...) is True. Confirmed in 2.7.

Example

def func():
    return False

if func:
    print('true')
else:
    print('false')

# true

if func():
    print('true')
else:
    print('false')

# false

Addictive pattern

class Test(object):
    def __init__(self):
        self._flag = False

    #here@I intended to add property but forgot to add it
    def flag(self):
        print('test flag')
        return self._flag
    
# ---

if __name__ == '__main__':
    test = Test()

    #I think it's a property, so call it without parentheses
    if test.flag:
        print('true')
    else:
        print('false')

# 'test flag'Is not printed
# 'true'Only printed

It's a mistake, but isn't it? No, I'm just too shobo ...

Recommended Posts

[python] Value of function object (?)
[Python3] Rewrite the code object of the function
[Python] Etymology of python function names
[Python] Calculate the average value of the pixel value RGB of the object
[Python] function
python function ②
[OpenCV; Python] Summary of findcontours function
Python built-in object
python enumerate function
Python> function> Closure
[Python] Generator function
Python built-in object
Basics of Python ①
Basics of python ①
Copy of python
Python> function> Inner function
Python function decorator
Introduction of Python
Draw a graph of a quadratic function in Python
Example of taking Python> function> * args as arguments
Get the caller of a function in Python
Find the divisor of the value entered in python
[Python] Operation of enumerate
List of python modules
About function arguments (python)
Function execution time (Python)
Unification of Python environment
Copy of python preferences
Basics of Python scraping basics
[python] behavior of argmax
Usage of Python locals ()
the zen of Python
Python function argument summary
Installation of Python 3.3 rc1
Python print function (sequel)
Python: About function arguments
Object oriented in python
Time floor function (Python)
# 4 [python] Basics of functions
Basic knowledge of Python
Sober trivia of python3
Summary of Python arguments
About Python3 ... (Ellipsis object)
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Set function of NumPy
Various processing of Python
Do not specify a mutable object (list type, dictionary type, etc.) as the initial value of the function argument of python.
[Cinema 4D] function of check all object in scene
Python: Get a list of methods for an object
A python regular expression, or a memo of a match object
How to store Python function in Value of dictionary (dict) and call function according to Key
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
[Python] Correct usage of map
Try to get the function list of Python> os package
Towards the retirement of Python2
Create a function in Python
Summary of python file operations
Summary of Python3 list operations
Python --Quick start of logging