《笨办法学Python》 第9课手记
2016-01-09 18:11
477 查看
《笨办法学Python》 第9课手记
这节课终于有一点新内容了,新内容也蛮容易理解的。原代码如下:
# Here's some new stuff, remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\nfeb\nMar\nApr\nMay\nJune\nJul\nAug" print "Here are the days: ", days print "Here are the months: ", months print""" Three's something going on here. With the three double-quotes. We'll be able to type as much as we like Even 4 lines if you want, or 5,or 6. """
结果如下:
\n是格式控制字符,相当于回车,表示到这里要换行。
另外,原代码的写法不推荐 至少在\n后加空格,才是更好的写法,空格可以使代码更清楚。作者明明在之前都是有空格的习惯的,你看=号前后都有空格,不知道到这里为什么不加空格了=.=。
前后用三个引号括起来可以print多行字符串。
你可能会想当然认为,那我用双引号不是也可以吗?
事实上,是不行的,双引号会报错:
我推测可能解释器将英文句号视为一个字符串的结束标志。By the way,将英文句号改为英文逗号依然会报错。
Python这个语言简单易学是由于在任何操作只提供最好的方法来实现,这也意味着同一个操作不能以多种形式实现,这点区别于C语言,而且与perl完全相反。
相关文章推荐
- Python 线程、进程和协程
- numpy实用技巧(一)
- python文件处理方式
- python之线程学习
- python面向对象特性----mutable, immutable, 函数传参
- python crc计算器
- python新手笔记之python继承
- Python新手笔记之python迭代器遍历列表
- python新手笔记之包和模块的引入
- python新手笔记之python高级函数编程
- python学习――――模块subprocess
- Python Flask 开发环境搭建(Windows)
- ubuntu14.04 server python3.4 安装 numpy scipy matplotlib
- 使用python 提取网页的特定数据转
- python入门笔记(Day4)--map,reduce
- Python FTP 文件上传 例程
- ubuntu14.04 server python2.7 安装 numpy scipy matplotlib
- python运维笔记第一节
- ubuntu14.04 server python3 安装matplotlib失败及解决方法
- python大小写转换