1.定义一个列表:[1, 2, 3] a.向列表中结尾增加一个元素4 b.在列表中元素4之前插入7 c.定义另一个列表2:[11, 12, 13], 用列表1去和并列表2 d.弹出(remove and return)7这个元素 e.倒序列表 d.对列表进行排序
list_sun = [1, 2, 3]
print(list_sun)
list_sun.extend([4])
print(list_sun)
list_sun.insert(3, 7)
print(list_sun)
list_sun2 = [11, 12, 13]
sum_sun = list_sun + list_sun2
print(sum_sun)
value = sum_sun.pop(3)
print(value, sum_sun)
sum_sun.reverse()
print(sum_sun)
sum_sun.sort()
print(sum_sun)
2.定义一个字典:{“zhangsan”: 18, “lisi”: 20} a.向字典中添加一个元素 wangwu: 31 b.访问字典中的元素: 访问key为sunwukong, 且程序不能出错 c.定义一个字典2{“sunwukong”: 28}, 用字典去合并字典2 d.获取字典所有的item: key和value e.获取字典的所有keys f.获取字典的所有values h.弹出字典的item
dict_sun = {"zhangsan": 18, "lisi": 20 }
print(dict_sun)
dict_sun["wangwu"] = 31
print(dict_sun)
print(dict_sun.get(3, "sunwukong"))
dict_sun2 = {"sunwukong": 28}
dict_sun3 = (dict(dict_sun, **dict_sun2))
print(dict_sun3)
print(dict_sun3.items())
print(dict_sun3.keys())
print(list(dict_sun3.keys()))
print(dict_sun3.values())
print(list(dict_sun3.values()))
print(dict_sun3.popitem())
dict_sun3 = dict_sun3.popitem()
print(dict_sun3)
3.集合 a.定义一个空集合 b.将列表[1, 2, 3, 4, 5, 4, 3, 2, 1]转换为set c.将字符串"12321"转成集合 d.将字节b’123321’转成集合
set_sun = set()
print(set_sun, type(set_sun))
set_sun = {1, 2, 3, 4, 5, 4, 3, 2, 1}
print(set_sun, type(set_sun))
print(set("12321"))
print(set(b"123321"))
|