python not and True 小练习

a = [i for i in range(10) if not(i % 2) and i % 3]   #一假则假
print(a)
'''
相当于:                           #youtube 小甲鱼搬运:因为true=1 false=0 如果能被2整出那么余数为0所以要用not
'''
a = range(10)
b = []
for i in a:
    if not (i % 2) and i % 3 :
        b.append(i)
print(b)
#>>>结果 
#[2, 4, 8]
#[2, 4, 8]

猜你喜欢

转载自blog.csdn.net/qq_35515661/article/details/81262433
今日推荐