标签:val 变量 if语句 字符串类型 test div not 而不是 and
#1.
#A:if语句
Test = [1, 2, 3, 4, 5, 6]
for value in Test: #注意:不能少
if 0 == value % 2 and 0 == value % 3: #注意:不能少
print("Type1", end = " ")
elif 0 == value % 2 or 2 == value % 3: #注意:不能少 这里是 elif 而不是 else if
print(‘Type2‘, end = " ")
else: #注意:不能少
print("Type3", end = " ")
#Type3 Type2 Type3 Type2 Type2 Type1
print("")
#2.
#A:not in
Test = [2, 3, 4]
Test1 = [1, 2, 3]
for value in Test:
if value not in Test1:
print("not in: " + str(value), end = ‘ ‘)
print("")
#not in: 4
#3.
#A:当变量是字符串类型且长度不为0,变量是列表(元组)类型且元素个数不为0时,充当if条件为True
Test = [1, 2, 3]
if Test:
print("not Null") #not Null
Test = (1, 2, 3)
if Test:
print("not Null") #not Null
Test = "Str"
if Test:
print("not Null") #not Null
标签:val 变量 if语句 字符串类型 test div not 而不是 and
原文地址:http://www.cnblogs.com/szn409/p/6505277.html