"""
name_list = ['Sean','Chan',666,'YL',True]
#定义空列表
a = []
b = list()
print(name_list)
print(type(name_list))
"""
"""
my_list = [[1,2,3],[4,5,6]]
print(my_list)
print(type(my_list))
"""
"""
# 列表中下表从左到右,从0开始
name_list = ['Sean','Chan',666,'YL',True]
#随意取用列表内元素,但超出索引范围会报错
print(name_list[0],name_list[1],name_list[3],name_list[2])
#两层下表索引,依然按顺序排列
my_list = [[1,2,3],[4,5,6]]
print(my_list[0][1],my_list[1][2]) #获取元素2与6
"""
"""
name_list = ['Sean','Chan',666,'YL',True]
index = name_list.index('YL')
print(f"YL 在列表中的索引值是:{index}")
# 如果元素不在列表内,用index查找该元素就会报错
#print(f"HELLO 在列表中的索引值是:{name_list.index('HELLO')}")
"""
"""
my_list = [[1,2,3],[4,5,6]]
my_list[0][0] = 100
print(f"列表被修改元素值后结果是:{my_list}")
"""
"""
name_list = ['Sean','Chan',666,'YL',True]
name_list.insert(0,'HAHA')
# 插入后,原本的元素往后靠
print(name_list)
"""
"""
name_list = ['Sean','Chan',666,'YL',True]
name_list.append('HAHA')
print(name_list)
my_list = [[1,2,3],[4,5,6]]
name_list.extend(my_list)
print(name_list)
"""
"""
name_list = ['Sean','Chan',666,'YL',True]
del name_list[2]
print(name_list)
element = name_list.pop(3) #该方法可以返回取出值
print(name_list)
print(f"通过pop方法取出的元素是:{element}")
"""
"""
num_list = [1,2,4,3,4]
num_list.remove(4) #只删除第一个找到的元素(从前到后)
print(num_list)
"""
"""
num_list = [1,2,4,3,4]
num_list.clear()
print(num_list)
"""
"""
num_list = [1,2,4,3,4]
print(num_list.count(4)) #输出结果为2
"""
"""
num_list = [1,2,4,3,4]
print(len(num_list)) #输出结果为5
"""
"""
列表特点总结:
1. 可容纳多个元素,2**63-1个;
2. 元素混装
3. 数据是有序存储的
4. 允许重复数据的存在
5. 可以修改元素
"""
"""
age_list = [21,25,21,23,22,20]
age_list.append(31)
age_list.extend([29,33,30])
first_element = age_list[0]
last_element = age_list[-1] #-1索引列表中最后一个元素
print(age_list)
print(f"元素31在列表中的下标位置为:{age_list.index(31)}")
"""
def list_while_func():
name_list = ['Sean','Chan',666,'YL',True]
index = 0
while index < len(name_list):
print(f"列表元素为:{name_list[index]}")
index += 1
def list_for_func():
name_list = ['Sean','Chan',666,'YL',True]
for object_1 in name_list:
print(f"列表元素为:{object_1}")
num_list = [1,2,3,4,5,6,7,8,9,10]
def while_func():
index = 0
even_list_1 = []
while index < len(num_list):
if num_list[index]%2 == 0:
even = num_list[index]
even_list_1.append(even)
index += 1
print(f"通过while循环,从列表中取出偶数,组成新列表:{even_list_1}")
def for_func():
even_list_2 = []
for even in num_list:
if even%2 == 0:
even_list_2.append(even)
print(f"通过for循环,从列表中取出偶数,组成新列表:{even_list_2}")
"""
t1 = (1,"Hello",True) #不限定类型
t2 = ()
t3 = tuple()
t4 = ("HEHE",) #注意,若元组内只有单个元素时,要在元素后面加','
print(f"各变量类型是{type(t1),type(t2),type(t3),type(t4)}")
t5 = ((1,2,3),(4,5,6)) #嵌套元组
num = t5[1][1]; print(num) #取出元组内元素5
"""
"""
t6 = ("Sean","Chan",666,666)
print(f"t6中元素“666”的个数是{t6.count(666)}")
print(f"t6中元素的个数是{len(t6)}")
print(f"t6中第Chan元素下标是{t6.index("Chan")}")
"""
"""
t7 = (1,2,["HEHEHE","HAHAHA"])
print(f"t7的内容是:{t7}")
t7[2][0] = "Sean"
t7[2][1] = "Chan"
print(f"t7的内容是:{t7}")
"""
"""
# 1.定义一个元组
stu_info = ('Sean Chan', 18, ['Gaming','Music'])
# 2.询问年零所在的下标位置
print(f"年龄信息所在的下标为:{stu_info.index(18)}")
# 3.查询学生姓名
print(f"学生姓名为:{stu_info[0]}")
# 4.删除学生爱好中的Gaming
stu_info[2].pop(0) ###重要!!!
print(f"学生{stu_info[0]}的爱好为:{stu_info[2]}")
# 5.增加爱好:Coding到爱好list内
stu_info[2].append('Coding') ###重要!!!
print(f"学生{stu_info[0]}的爱好为:{stu_info[2]}")
"""
"""
my_str = "Sean Chan"
value_1 = my_str[0]
value_2 = my_str[-9] #空格也算长度
print(f"value_1的值是{value_1}")
print(f"value_2的值是{value_2}")
"""
"""
new_my_str = my_str.replace("Sean","YL")
print(new_my_str)
"""
"""
my_str = "YL named SW"
my_str_list = my_str.split(" ")
print(f"将字符串通过分隔符” ”分割后是{my_str_list}")
"""
"""
my_str = " Hello World! "
print(my_str.strip()) #不传参就是默认去除空格
"""
"""
my_str = "12Hello World!21"
my_str_1 = my_str.strip("12") #此处是将12两个字符串分割成1与2,这样就能识别12或21
print(my_str_1)
"""
"""
my_str = "12Hello World!21"
print(my_str.count("1"))
"""
"""
my_str = "12Hello World!21"
print(len(my_str))
"""
"""
my_str = "12Hello World!21"
for x in my_str:
print(x,end=' ')
"""
"""
str_1 = "Learn IT for IT job in IT blog"
# 统计字符串中有多少“IT”字符
print(f"字符串{str_1}中有:{str_1.count("IT")}个IT字符")
#将字符串内空格全部替换为字符“|”
str_2 = str_1.replace(" ", "|")
print(f"字符串{str_1},被替换空格后,结果:{str_2}")
#按照“|”进行字符串分隔,得到列表
list_1 = str_2.split("|")
print(f"字符串{str_2},按照|分隔后,得到:{list_1}")
"""
"""
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8]
result_1 = my_list[0:4] #注意:不包含结束位的元素
result_5 = my_list[5:0:-1]
print(result_1)
print(result_5)
my_tuple = (0, 1, 2, 3, 4, 5, 6, 7, 8)
result_2 = my_tuple[:]
result_6 = my_tuple[::-2]
print(result_2)
print(result_6)
my_str = "012345678"
result_3 = my_str[::2]
result_4 = my_str[::-1]
print(result_3)
print(result_4)
"""
"""
# 方式1
my_str = "万过薪月,TI搞,nohtyP学"
rever_my_str = my_str[::-1]
my_list = rever_my_str.split(",")
print(f"取出的切片为:{my_list[1]}")
# 方式2
result = my_str[7:4:-1]
print(f"取出的切片为:{result}")
# 方式3
result_1 = my_str[5:8][::-1] #取出列表,然后列表倒序
print(f"取出的切片为:{result_1}")
"""
"""
print(f"my_set_1的内容是{my_set_1}") # 去重了,并且无序,多运行几次
print(f"my_set_2的内容是{my_set_2}") # 空集合
print(f"my_set_1的类型是{type(my_set_1)}")
print(f"my_set_2的类型是{type(my_set_2)}")
"""
"""
my_set_2.add("Python")
print(f"my_set_2的内容是{my_set_2}")
my_set_2.add("Python") #去重,再添加无意义
print(f"my_set_2的内容是{my_set_2}")
"""
"""
my_set_2.remove("Python")
print(f"my_set_2的内容是{my_set_2}")
"""
"""
element_1 = my_set_1.pop()
print(f"从my_set_1取出的元素是{element_1}") #随机取
"""
"""
my_set_1.clear()
print(f"my_set_1的内容被清空后是{my_set_1}")
"""
"""
my_set_1 = {"Sean", "Chan", "666","YL"}
my_set_2 = {"Sean", "Chan"}
my_set_3 = my_set_1.difference(my_set_2)
print(f"my_set_3的内容是{my_set_3}")
"""
"""
my_set_1 = {"Sean", "Chan", "666","YL"}
my_set_2 = {"Sean", "Chan"}
my_set_1.difference_update(my_set_2)
print(f"my_set_1修改的内容是{my_set_1}")
print(f"my_set_2的内容是{my_set_2}")
"""
"""
my_set_1 = {"Sean", "Chan"}
my_set_2 = {"666","YL","Chan"}
my_set_3 = my_set_1.union(my_set_2)
print(f"合并集合:my_set_3的内容是{my_set_3}") #已去重
"""
"""
my_set_1 = {"Sean", "Chan", "666","YL", "Chan"}
num = len(my_set_1)
print(f"my_set_1的元素数量有{num}个") #已去重
"""
"""
my_set_1 = {"Sean", "Chan", "666","YL", "Chan"}
for x in my_set_1:
print(x, end=' ')
"""
"""
my_list = ['Sean', 'Chan', 'YL', 'YL', '666', 'NCHU', 'WYU', '666']
# 定义一个空集合
my_set = set()
#通过for循环遍历列表并将列表元素添加至集合中,最后打印输出集合
for x in my_list:
my_set.add(x)
print(f"集合中的内容是:{my_set}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
print(f"字典1的内容是:{my_dict},类型是{type(my_dict)}")
"""
"""
my_empty_dict_1 = {}
my_empty_dict_2 = dict()
print(f"字典2的内容是:{my_empty_dict_1},类型是{type(my_empty_dict_1)}")
print(f"字典3的内容是:{my_empty_dict_2},类型是{type(my_empty_dict_2)}")
"""
"""
my_dict = {"Sean": 88, "Sean": 93, "YL": 99}
print(f"字典1的内容是:{my_dict}") #后一个被前一个覆盖了
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
score = my_dict["Sean"]
print(f"Sean的分数是:{score}")
"""
"""
stu_score_dict = {
"Sean":{
"语文": 77,
"数学": 88,
"英语": 88},
"Chan":{
"语文": 87,
"数学": 76,
"英语": 90},
"YL":{
"语文": 78,
"数学": 89,
"英语": 94}
}
print(stu_score_dict)
score = stu_score_dict["Chan"]["语文"]
print(f"Chan的语文分数是:{score}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
my_dict["HEHE"] = 85
print(f"新增后:{my_dict}")
my_dict["HEHE"] = 99
print(f"修改后:{my_dict}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
score = my_dict.pop("Sean")
print(f"Sean被删除后:{my_dict},Sean的考试分数是:{score}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
my_dict.clear()
print(f"字典被清空了,内容是{my_dict}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
keys = my_dict.keys()
print(f"字典中全部的key是{keys}")
"""
"""
# 方式1:获取全部key来完成遍历
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
keys = my_dict.keys()
for key in keys:
print(f"字典的key是:{key}", end='\t\t')
print(f"字典的value是:{my_dict[key]}")
# 方式2:直接对字典进行for循环,每次循环直接得到key
for key in my_dict:
print(f"字典的key是:{key}", end='\t\t')
print(f"字典的value是:{my_dict[key]}")
"""
"""
my_dict = {"Sean": 88, "Chan": 93, "YL": 99}
num = len(my_dict)
print(f"字典的元素数量为:{num}")
"""
department_message = {
"Sean": {
"department": "Tech",
"salary": 16000,
"rank": 1
},
"Chan": {
"department": "Market",
"salary": 23000,
"rank": 2
},
"YL": {
"department": "Market",
"salary": 28000,
"rank": 3
},
"Zhang": {
"department": "Market",
"salary": 17000,
"rank": 1
},
"Liu": {
"department": "Market",
"salary": 24000,
"rank": 2
}
}
print("全体员工当前信息如下:")
for x in department_message:
print(f"{x}{department_message[x]}")
for x in department_message:
if department_message[x]["rank"] == 1:
department_message[x]["rank"] += 1
department_message[x]["salary"] += 4000
print("级别为1的员工升职加薪后信息如下:")
for x in department_message:
print(f"{x}{department_message[x]}")