Python学习笔记
2017-12-11 16:18
190 查看
工作需要熟悉一下Python, 在看Learn Python the hard way, 记点笔记
--------------------------------------------------------------------------------------------------------
What is the difference between %r and %s?
We use %r for debugging, since it displays the “raw” data of the variable, but we use %s andothers for displaying to users.
Example:
What’s the point of %s and %d when you can just use %r?
The %r is best for debugging, and the other formats are for actually displaying variables to users.
Why do you put ' (single- quotes) around some strings and not others?
Mostly it’s because of style, but I’ll use a single- quote inside a string that has double- quotes.
* 在print中的用法:
,在print中的用法: 表示当前行还没结束, 下面一个print的string还会放在同一行中, 比如
会返回
而如果把 end6 后面的逗号去掉, 则会变成
print """ 可以用来打印任意长度的字符串,比如
--------------------------------------------------------------------------------------------------------
What is the difference between %r and %s?
We use %r for debugging, since it displays the “raw” data of the variable, but we use %s andothers for displaying to users.
Example:
>>> x = "There are %d types of people." % 10 >>> print "said %r" % x said 'There are 10 types of people.' >>> print "said %s" % x said There are 10 types of people.
What’s the point of %s and %d when you can just use %r?
The %r is best for debugging, and the other formats are for actually displaying variables to users.
Why do you put ' (single- quotes) around some strings and not others?
Mostly it’s because of style, but I’ll use a single- quote inside a string that has double- quotes.
>>> print "I also said: '%s'." % y I also said: 'There are 10 types of people.'.
* 在print中的用法:
>>> print "." * 10 # what'd that do? ..........
,在print中的用法: 表示当前行还没结束, 下面一个print的string还会放在同一行中, 比如
print "." * 10 # what'd that do? end1 = "C" end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r" # watch that comma at the end. try removing it to see what happens print end1 + end2 + end3 + end4 + end5 + end6, print end7 + end8 + end9 + end10 + end11 + end12
会返回
$ python ex2.py .......... Cheese Burger
而如果把 end6 后面的逗号去掉, 则会变成
$ python ex2.py .......... Cheese Burger
print """ 可以用来打印任意长度的字符串,比如
>>> print """ ... Hi hello world I ... I like something good, bad, etc. ... heheh ... hahaha ..... example! ... """ Hi hello world I I like something good, bad, etc. heheh hahaha ..... example!
相关文章推荐
- python 学习笔记(4)-转载
- python学习笔记-Day08--(socket和socketserver)
- python可视化学习笔记
- python学习笔记【2017-12-10】
- Python入门学习笔记之Python模块
- Python学习笔记 Module
- 学习笔记-小甲鱼Python3学习第二十二讲:函数:递归是神马
- [2015.2.11] python学习笔记 IO编程
- Python学习笔记(八)爬虫基础(正则和编解码)
- Python学习笔记——列表
- python及tensorflow代码学习使用笔记
- Python学习笔记1-环境搭建
- python的学习笔记/002-2(2018-5-19)
- python学习笔记(五)之字典2
- Python学习笔记(二) 之 错误,调试,测试
- Python Web 开发学习 - 学习笔记(2)- 启动Python
- python的学习笔记/002-4(2018-5-20)
- Python 的类学习笔记一
- Day2----Python学习之路笔记(2)
- Python爬虫框架Scrapy 学习笔记 10.2 -------【实战】 抓取天猫某网店所有宝贝详情