Python编程-Hello World!
本文中的历程代码参考自网上《简明Python教程.chm》编写,希望对大家有用,下载地址:
2014年5月7日,本程序请参考简明Python教程第四章。
第一个Hello World程序,基本输出,以及字符和变量操作。
中文注释出错的解决办法是在文件开始部分添加下面一句:
# -*- coding: utf-8 -* # 其作用是允许输入非英文,使用utf-8 编码
1 #!/usr/bin/python 2 # -*- coding: utf-8 -* 3 # Filename : hello.py 4 5 ## 6 print '\nHello word!\n' 7 8 ##三引号打印多行字符 9 print '''This is a multi-line string. 10 This is the first line. 11 This is the second line. 12 \"What\'s your name? \", I asked. 13 He said \"Bond, James Bond.\" 14 ''' 15 16 #自然字符串不需要转义字符 17 print r"Newlines are indicated by \n" 18 print "So we try this rule.\nDisplay on the second line." 19 20 #Unicode字符串打印非英文字符 21 print u"This is a Unicode string: 拥抱世界!"
第二个Python例程主要是对整形、浮点型、字符串的基本操作。
1 #!/usr/bin/python 2 # -*- coding: utf-8 -* 3 # File name: var.py 4 # Test for varify application 5 6 i = 5; 7 print i; 8 i = i + 1; 9 print i; 10 11 f = 12.03*25; 12 print f; 13 14 S = '''This is a multi-line sting. 15 The second line.'''; 16 print S;