美文网首页
Python学习笔记

Python学习笔记

作者: Jeremy_Mi | 来源:发表于2017-06-22 21:35 被阅读38次

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.listextendappend的区别: 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.strformat用法:
>>>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学习笔记

      本文链接:https://www.haomeiwen.com/subject/sqqqcxtx.html