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)
网友评论