Quick to learn Python rules
2015-08-20 17:02
756 查看
以下这张图简要地介绍了Python的语法规则 ![Quick Python Script Explanation for Programmer](https://img-blog.csdn.net/20150820165857656)
由于Python2.x与Python3.x之间的一些语法区别,对应的修改后的代码如下:
# _*_ coding: utf-8 _*_ # Qucik Python Script Explanation for Programmers import os #导入代码模块,os.py def main(): print("Hello World") print("This is Shaobing Huang's greeting.") print("This is the greeting from yours.") foo(5, 10) #funciton call print('='*20) print("Current working directory is ",end='') print(os.getcwd()) counter=0 counter+=1 food=['apples','oranges','cats'] for i in food: print("I like to eat %s" %i) print("count to ten:") for i in range(10): print(i) def foo(param1, secondParam): res= param1 + secondParam print("%d plus %d is equal to %d" %(param1 ,secondParam,res)) if res<50: print("foo") elif (res>=50) and ((param1 == 42) or (secondParam == 24)): print("bar") else: print("moo") return res #This is one-line comment ''' A multi- line string, but can also be a multi-line comment. ''' if __name__ == '__main__': main()
链接如下:
http://www.crifan.com/files/doc/docbook/python_beginner_tutorial/release/htmls/ch05_python_grammar_and_basics.html
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法