python 学习手册 第二部分重读!
容易忘记点
- 字符串格式化 s.format()
In [29]: 'hello {0} {name},today is {date:%Y-%m-%d %H:%M:%S}'.format(1,name='lsl',date=n)
Out[29]: 'hello 1 lsl,today is 2016-02-22 21:17:08'
- 转义序列代表特殊性字节
\n 换行 \uhhhh unicode 16 \Uhhhhhhhhh unicode 32 \xhh 十六进制 \o 八进制
In [30]: '\x23'
Out[30]: '#'
In [31]: '\x94'
Out[31]: '\x94'
In [32]: '\x12'
Out[32]: '\x12'
In [33]: '\x24'
Out[33]: '$'
-
字典无序集口
-
bool 类型
In [34]: bool('23')
Out[34]: True
In [35]: bool('')
Out[35]: False
In [36]: bool([])
Out[36]: False
In [37]: bool({})
Out[37]: False
- while else 只有当while 正常离去时才会执行.
代码格式
注意使用\不利点
if a == b and c == d and \
d == e and f == g:
print('old')
if (a == b and c == d and
d == e and f == g):
print('new')
x = 1 + 2 + 3 \
+4
x = 1 + 2 + 3
+4
长字符串写法
S = """
aaaa
bbbb
cccc
"""
S = (
'aaaa'
'bbbb'
'cccc'
)