简明Python教程:http://old.sebug.net/paper/python/ch06s05.html
很适合入门学习。
编程语言的学习无他,就是看书或网上资料,然后马上写代码试验。看的多了,写的多了,语言的特性什么都会有更好跟直接的体会。
break语句
break
语句是用来 终止 循环语句的,即哪怕循环条件没有称为False
或序列还没有被完全递归,也停止执行循环语句。
一个重要的注释是,如果你从for
或while
循环中 终止 ,任何对应的循环else
块将不执行。
step1,编写python代码,保存为.py文件
while True: s = raw_input('enter an str:') if s == 'quit': break print 'Length of the string "'+s+'" is,',len(s)
step2,运行文件。输入值得到如下试验结果。
enter an str:1 Length of the string "1" is, 1 enter an str:2 Length of the string "2" is, 1 enter an str:232134 Length of the string "232134" is, 6 enter an str:skdjflas Length of the string "skdjflas" is, 8 enter an str:skdjflaksdjflas你好 Length of the string "skdjflaksdjflas你好" is, 21 enter an str:quit ***Repl Closed***