Python_Multi_way decision

来源:互联网 发布:java多线程应用场景 编辑:程序博客网 时间:2024/06/10 07:45
From Vit: blog.csdn.net/svitter
#Multi_way decisionx = int(raw_input("Please input enter an integer:"))#input type is string, need to be translate.and get \n to;if x < 0:    x = 0;    print "Negative changed to Zero";elif x == 0:    print "Zero";else:    print "More";# Loops Lista = ['cat', 'windows', 'defense trate']for x in a: #check all of the array a    print x, len(x)#Define and invode functiondef sum(a, b):    return a + b;func = sumr = func(5, 6);print r;#Defines function with defalt argumentdef add(a,b=2):    return a+br = add(1)print rr = add(1, 5)print r#a useful functionprint "a is: " + str(a)a = range(5, 10)print aa = range(-2, -7)print aa = range(-7, -2)print aa = range(-2,-11,-3) #The 3rd parameter stands for stepprint a

0 0