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
,因为它是非空的。看