1.算术运算符
d=10
d/=8 #其中d=1.25
d//=8 #其中d=1 直接取整数(非四舍五入)
3.0//2=1.0
CJ: **幂运算–优先级
当其左侧为一元运算符,其优先级高于一元运算符
当其右侧为一元运算符,其优先级低于一元运算符
举例:
-3**2=-9 #相当于-(3**2)
3**-2=0.111111 #相当于3的-2次方
2.列表[ ]
list1=list[:]
list2=list #列表浅拷贝
list3=list1+list2 #拼接列表其中+左右两侧数据类型必须一致 一般建议使用extend方法
temp=[12,'jerry',[3,45]]
>>>3 not in temp
True #只能判断一层
list=['jerry',1,24]
list1=list[:]
list2=list
list.append('Phil')
print("list:{},地址为:{}".format(list,id(list)))
print("list1:{},地址为:{}".format(list1,id(list1)))
print("list2:{},地址为:{}".format(list2,id(list2)))
运行结果:
list:['jerry', 1, 24, 'Phil'],地址为:2377760461320
list1:['jerry', 1, 24],地址为:2377760461832
list2:['jerry', 1, 24, 'Phil'],地址为:2377760461320
3.元组Tuple
对于元组来说,逗号’,'是关键
tuple=(1,2,3,4,5)
temp=(1) #其类型为int
temp=(1,) #其类型为tuple
temp=2,3,4,5 #其类型为tuple
temp=() #表示空元组
8*(8)=64
8*(8,) #表示8个元素为8的元组(8,8,8,8,8,8,8,8)
tu=('王','李','赵')
tu=tu[:1]+('郑',)+tu[1:] #其中逗号不能省略,因为+两边的数据类型要保持一致 tu=('王','郑','李','赵')
4.字典
不是序列,字典里面的顺序不一
a={1:'one',2:'two',3:'three'}
b=a.copy()#浅拷贝
c=a
c[4]='four'
print("a:{},地址为:{}".format(a,id(a)))
print("b:{},地址为:{}".format(b,id(b)))
print("c:{},地址为:{}".format(c,id(c)))
运行结果:
a:{1: 'one', 2: 'two', 3: 'three', 4: 'four'},地址为:2377789929896
b:{1: 'one', 2: 'two', 3: 'three'},地址为:2377789929976
c:{1: 'one', 2: 'two', 3: 'three', 4: 'four'},地址为:2377789929896