1. 程式人生 > >python 迴圈以及迴圈控制

python 迴圈以及迴圈控制

import time

s = "Hello"
l = [1, 2, 3, 'a', 'b']
t = (7, 8, 9, 'c', 'd')

d = {1:111, 2:222, 5:555, 3:333}


for k, v in d.items():
    print k, v
    # time.sleep(1)
else:
    print "Ending ..."


for x in range(1, 11):
    print x
    if x == 3:
        pass
    if x == 2:
        print 'Hello 2'
        continue
    if x == 5:
        pass
        # exit()
    if x == 6:
        break
    print "#"*50
else:
    print "Normal Ending..."

x = ''
while x != 'q':
    print "hello"
    x = raw_input("please input something, q for quit:")
    if not x:
        break
    if x == "c":
        continue
    print "once more time ~~~~~~"
else:
    print "ending..."