首页 > 其他 > 详细

第五章 if语句

时间:2017-03-05 14:49:14      阅读:213      评论:0      收藏:0      [点我收藏+]
#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

  

第五章 if语句

原文:http://www.cnblogs.com/szn409/p/6505277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!