Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么一组虚假的对象是真实的?_Python_Python 3.x - Fatal编程技术网

Python 为什么一组虚假的对象是真实的?

Python 为什么一组虚假的对象是真实的?,python,python-3.x,Python,Python 3.x,在最近的一个项目中遇到了这个问题,并好奇为什么会这样 test_ = None test_1 = [] test_2 = ([], None) if test_: print('hello') if test_1: print('hello') if test_2: print('hello') > hello 因为非空元组的计算结果为True,因为它是非空的。看

在最近的一个项目中遇到了这个问题,并好奇为什么会这样

test_ = None
test_1 = []
test_2 = ([], None)

if test_:
    print('hello')

if test_1:
    print('hello')

if test_2:
    print('hello')
> hello
因为非空元组的计算结果为
True

,因为它是非空的。看