Beginning Python From Novice to Professional (5) - 条件与循环
来源:互联网 发布:面对疾风吧网络意思 编辑:程序博客网 时间:2024/04/30 14:29
条件与循环
条件执行:
name = raw_input('What is your name? ')if name.endswith('Gumby'):print 'Hello, Mr.Gumby'
What is your name? GumbyHello, Mr.Gumby
name = raw_input('What is your name? ')if name.endswith('Gumby'):print 'Hello, Mr.Gumby'else:print 'Hello, stranger'多个条件:
num = input('Enter a number: ')if num > 0:print 'The number is positive'elif num < 0:print 'The number is negative'else:print 'The number is zero'
Enter a number: 5The number is positive
Enter a number: -1The number is negative
Enter a number: 0The number is zerowhile循环:
x = 1while x<=100:print xx+=1for循环:
numbers = [0,1,2,3,4,5,6,7,8,9]for number in numbers:print number
0123456789循环中的else:
for n in range(99,81,-1):root = sqrt(n)if root == int(root):print nbreakelse: #只在没有调用break时执行print "Didn't find it!"
1 0
- Beginning Python From Novice to Professional (5) - 条件与循环
- Beginning Python: From Novice to Professional
- Beginning Python From Novice to Professional (3) - 列表操作
- Beginning Python From Novice to Professional (6) - 函数使用
- Beginning Python From Novice to Professional (7) - 类
- Beginning Python From Novice to Professional (8) - 文件方法
- Beginning Python From Novice to Professional (9) - Socket
- Beginning J2EE 5: From Novice to Professional
- 《Beginning Python From Novice to Professional》学习笔记一:String
- 《Beginning Python From Novice to Professional》学习笔记二:Sequence
- 《Beginning Python From Novice to Professional》学习笔记三:List
- 《Beginning Python From Novice to Professional》学习笔记四:Tuple
- 《Beginning Python From Novice to Professional》学习笔记六:Dictionary
- 《Beginning Python From Novice to Professional》学习笔记七:Statement
- 《Beginning Python From Novice to Professional》学习笔记八:Abstraction
- 《Beginning Python From Novice to Professional》学习笔记十:Exception
- 《Beginning Python From Novice to Professional》学习笔记十一:__Magic__
- 《Beginning Python From Novice to Professional》学习笔记十二:__Magic__
- W5500问题集锦(二)
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 女孩子工作中,可以把网页作为重点
- linux 时间同步
- C++ STL算法汇总
- Beginning Python From Novice to Professional (5) - 条件与循环
- Android推送方案分析(MQTT/XMPP/GCM)
- 在CentOS 7中安装与配置JDK8
- Linux tomca t图片服务器
- WebBrowser判断登录成功-WebBrowser-404错误-500错误-屏蔽消息窗口-Webbrowser判断是否加载成功
- gem5模拟器使用介绍(二)
- jquery查找各种节点
- activity之间参数传递&&获取activity返回值&&activity生命周期
- 安卓APP开发学习笔记(1)