附录C Python参考

Python是一种通用的编程和脚本语言。它的简单性和丰富的库使得快速开发一个符合现代技术需求的应用成为可能。Python代码写在后缀为.py文件中,可以用命令python执行。

以下为一个基于Python的简单程序,仅打印一行文本。

[输入]

source_code/appendix_c_python/example00_helloworld.py
print "Hello World!"

[输出]

$ python example00_helloworld.py
Hello World!

注释不会被Python执行。它以字符#开头,以行尾结束。

[输入]

# source_code/appendix_c_python/example01_comments.py
print "This text will be printed because the print statement is executed."
#这只是一个注释,不会被执行
#print "Even commented statements are not executed."
print "But the comment finished with the end of the line."
print "So the 4th and 5th line of the code are executed again."

[输出]

$ python example01_comments.py This text will be printed because the print statement ...

Get 精通数据科学算法 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.