黑松山资源网 Design By www.paidiu.com
字符串
字符串用''或者""括起来,如果字符串内部有‘或者",需要使用\进行转义
> print 'I\'m ok.' I'm ok.
转义字符\可以转义很多字符,比如\n表示换行,\t表示制表符,字符\本身也要转义,所以\\表示的字符就是\。当然如果不需要转义,可以使用r'':
> print '\\\t\\' \ > print r'\\\t\\' \\\t\
如果字符串内部有很多换行,用\n写在一行里不好阅读,为了简化,Python允许用'''…'''的格式表示多行内容:
> print '''line1 ... line2 ... line3''' line1 line2 line3
如果写成程序,就是:
print '''line1 line2 line3'''
可能出现的问题
中文编码问题
# coding = utf-8
结果报错:
SyntaxError: Non-ASCII character ‘/xe6'
所以最后改成了
# coding=utf-8
唉....
Unicode编码问题
Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. > len('中文') 6 > len(u'中文') 2 >
注意: 这个问题是由python编码导致的,详细的编码问题详见字符串和编码,但是在python 3.x中这个编码问题就不存在了:
Python 3.4.0 (default, Jun 19 2015, 14:20:21) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. > len('中文') 2 > len(u'中文') 2 >
输出
> print 'hello, world' hello, world > print 'The quick brown fox', 'jumps over', 'the lazy dog' The quick brown fox jumps over the lazy dog > print '100 + 200 =', 100 + 200 100 + 200 = 300
输入
> name = raw_input() Michael > name 'Michael' > print name Michael > name = raw_input('please enter your name: ') please enter your name:
注意: raw_input返回的永远是字符串,也就是说你输入一个int型,返回的是一个数字字符串,你需要进行转换:
> number = raw_input("输入一个整数:") 输入一个整数:123 > number '123' > number = int(raw_input("输入一个整数:")) 输入一个整数:123 > number 123
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮什么时候开始 s14瑞士轮开始时间介绍
- 晨报|《使命召唤21》全球发布预告 《异形:隔离》续作官宣开发中
- 隐形女联动毁灭博士?杰西卡·阿尔巴与小唐尼晒合影
- 《博德之门3》7号补丁发布后:Mod下载量达到2200万次!
- 徐璨宾《井底的蚯蚓》[FLAC/分轨][218.37MB]
- 王冰冰《Vaga Luna 月球漫游》[320K/MP3][62.76MB]
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[320K/MP3][59.79MB]
- 群星.1993-飞图合唱歌曲精丫飞图】【WAV+CUE】
- 王霏霏.2024-TOOOOO.BUSY(EP)【SNMUSIC】【FLAC分轨】
- 张宇.2016-好男人的情歌NEWXRCD【金牌大风】【WAV+CUE】
- 《食戟之灵》小林龙胆兔女郎比基尼版模型即将发售
- 重大里程碑!九号电动第500万台智能两轮电动车正式下线
- TGA主持人发文祝贺《暗喻幻想》 国外网友:提名稳了?
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号81~序号90)
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号91~序号100)