写出下面程序的运行结果。import copys1=[4,5,6]s2=s1s2[1]="nk"print(s1,s2)s3=s1[1:3]s3[1]="cn"print(s1,s3)s4=copy.deepcopy(s1)s4[1]=333print(s1,s4)s5=[4,[5,6]]s6=s5[1:3]s5[1][0]="cn"print(s5,s6)s7=copy.deepcopy(s5)s7[1]="nk"print(s5,s7)
查看答案
写出下面程序的运行结果。s1={1,2,3}s2=set([2,3,3,4])s1.add(3)s2.update('ab')s3=s1.intersection(s2)s4=s1.union(s2)s5=s1.difference(s2)s6=s1.symmetric_difference(s2)print(s1)print(s2)print(s3)print(s4)print(s5)print(s6)
写出下面程序的运行结果。d1={'name':"zhangsan",'sno':"001",'score':99}d2=dict().fromkeys(['radius','height'],0)print(d1)print(d2)d1.update({'age':19})d2.update(radius=10)print(d1)print(d2)del d1['age']height=d2.pop('height','not found')print(d1)print(d2)print(height)print(len(d1))print(len(d2))
写出下面程序的运行结果。s1=[1,2,3,4,5,6,7,8,9,10]s2=list(range(10,20))s3=s1[2:8:2]s4=s2[-8::-2]print(s1)print(s2)print(s3)print(s4)
写出下列程序的运行结果:class Student:def __init__(self,sno,name):self.sno=snoself.name=namedef __str__(self):return '学号:'+self.sno+',姓名:'+self.nameif __name__=='__main__':ls1=[23,56,12,37,28]ls1.sort()print(ls1)ls1.sort(reverse=True)print(ls1)ls2=[Student('1810101','李晓明'), Student('1810100','马红'),Student('1810102','张刚')]ls2.sort(key=lambda stu:stu.sno)for stu in ls2:print(stu)ls2.sort(key=lambda stu:stu.sno, reverse=True)for stu in ls2:print(stu)