5.Python基础 缩进与选择的关系
2015-08-05 21:31
639 查看
根据vamei前辈的博客学习的,原文地址:
/article/4673208.html
/article/4673208.html
######################################################### i = 2 x = 10 if i < 5: x = x + 1 #靠缩进来表示隶属关系 i = i + 7 print ("i =",i,",x =",x) #打印的时候数字前面和后面都会添加空格 #结果:i = 9 ,x = 11 ########################################################## j = 1 print ("old j:",j) if j > 0: print ("positive j") j = j + 1 elif j == 0: print ('j is 0') else: #注意此处有冒号: print ('negative j') j = j - 1 print ("new j:",j) ########################################################### if x < 12: x = x + 3 if x < 15: print ("if x < 15:") print ("if x < 12:") ############################################################ #结果: #i = 9 ,x = 11 #old j: 1 #positive j #new j: 2 #if x < 15: #if x < 12:把上面的程序保存为.py格式,按F5直接运行。
相关文章推荐
- Python之正则表达式
- 用python写MapReduce函数
- 使用Python开发windows桌面程序
- Python文档中if __name__ == '__main__'
- Python使用小技巧
- 简单性能测试: bottle vs flask
- Python列表去重
- TabError: Inconsistent use of tabs and spaces in indentation
- 如何像Python高手(Pythonista)一样编程
- Ubuntu上安装python开发环境pycharm
- Data manipulation primitives in R and Python
- 【Python】读取命令行参数、在PyDev中设置Python运行时的参数
- python argparse
- python 调用短信接口
- python urllib2, urllib使用
- python 绘图
- 【Python】 [基础] 条件判断 与 循环 与dict和set
- 5 个很好的 Python 面试题
- caffe python visualization程序解析
- Python装饰器