【笔记】 APEA-15-112 Python 3.0 Lecture 5 一维数组和元组
@ZYX 写于2018年07月10日
逻辑短路 logic short-cut
- 逻辑短路,False and xxx,直接返回False,不运行xxx;True or xxx同理
- print(42 or 11//0) = print(42) print(0 and 11//0) = print 0
- if(not(n%2)):print(odd) -----> not(0) == True not(1) == not(42) == False
数组 List
- method: len min max
- a=[1,2,3,"asa"] print(a[0])
- List的元素是可变的,与String不同
- L=[1,2,3] slice = L[1:]+ L[0]会崩溃,因为L[0]是int不是list。所以L[1:]+[L[o]]
- append和extend也可以解决
- L = [1,2,3,4] lst=L.extend([5,6]) print(lst) == None
- 数组赋值,b=a只是让b指向a的地址。a变b就变,b变a也变。
- List有index、in和count。但是List没有find。
- L.insert(index, element)
- non-destructive L=[1,2,3] A=L+[4] A[0] =42 L==[1,2,3]
- a[2,3,4,5,6,7,8] a.pop()==8 a.pop(0) == [3,4,5,6,7,8] a.pop[3] == [2,4,5,6,7,8]
- a.remove()不会返回任何值
- List.reverse不会返回,但是reversed(List)会返回反过来的List
- sort和sorted同理
- from copy import * 可以不写copy.。
元组 Tuple
- 和字符串一样,元组不能改变其任一目录上的元素
- (42)==42 (42,)==[42]
⇧