您的位置:首页 > 编程语言 > Python开发

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 print