Python编程-Hello World!

本文介绍了Python编程的基础知识,并通过实例演示了HelloWorld程序、变量操作和数据类型的基本使用。详细阐述了如何解决中文注释错误问题及多行字符串打印方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文中的历程代码参考自网上《简明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;

 

转载于:https://www.cnblogs.com/conservation/p/3722626.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值