关闭

4.2.1 - Flow Control Using If/Else Statements

140人阅读 评论(0) 收藏 举报
分类:
if 10 > 0:
    print("this is a true statement")
    
if None:  #none is equal to false
    print("this is a true statement")

if None:    
    print("this is a true statement")
else:
    print("this is a false statement")
    
test = "hello"     # string contains one or more characters will evaluate to true
test = ""  # an empty string evaluates to false

test =[1, 2, 3]   # list contains one or more element will evaluate to true
test = [] # empty list evaluates to false


#the same holds for dictionary, as well as tuple

  
test = 0   # 0 evalates to false, any other number will evaluate to true



import maya.cmds as cmds

sel = cmds.ls(sl=True)

if sel:
    for s in sel:
        print(s)
else:
    print("please select one or more objects")
    

if len(sel) >= 2:
    for s in sel:
        print(s)
elif len(sel) == 1:
    print("Please select at least two objects")
else:
    print("no object selected")
    
    
# the else statement is not required, when we don't type out the else statement, it's equals to the following statements

# else:
#     pass


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:474051次
    • 积分:10854
    • 等级:
    • 排名:第1679名
    • 原创:610篇
    • 转载:98篇
    • 译文:0篇
    • 评论:97条
    文章分类
    最新评论