1.退出python交互环境: Control + D
2.开启终端分屏: Command + D
3.字符串复制: 3 * 'ABC' == 'ABCABCABC'
4.字符串下标取值: 'Python'[2], 'Python'[-1]
5.range
用法: range(0, 10, 3), range(-10, -100, -30)
6.list
中extend
和append
的区别: extend
相当于append(contentof:)
7.list
用作栈效率较高(append, pop等方法), 用作队列效率较低, 队列应该使用deque
(popleft
, appendleft
方法)
8.[(x, x**2) for x in range(10)]
9.vec = [[1,2,3], [4, 5, 6], [7,8,9]], [num for elem in vec for num in elem], [[row[i] for row in vec] for i in range(3)] == list(zip(*vec))
10.set
操作符: a - b, a | b, a & b, a ^ b
11.str
布局:'ABC'.rjust(10)
,'ABC'.ljust(10)
, 'ABC'.center(10)
, '123'.zfill(5)
12.str
的format
用法:
>>>print('We are the {} who say "{}!"'.format('knights', 'Ni'))
>>>print('{1} and {0}'.format('spam', 'eggs'))
>>>print('This {food} is {adjective}.'.format(food='spam', adjective='absolutely horrible'))
>>>contents = 'eels'
>>>print('My hovercraft is full of {!r}.'.format(contents)) #(!a)代表ascii(),(!s)代表str(),()!r代表repr()
>>>print('The value of PI is approximately {0:.10f}.'.format(math.pi))等价于
>>>print('The value of PI is approximately %.10f.' % math.pi)
Python学习笔记
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...