from random import randint
import turtle as t
li = []
for i in range(10):
li.append(i)
print(li)
print([i for i in range(10)])
print([i + 100 for i in range(10)])
print([i**2 for i in range(10)])
name_list = [f"stu{i}" for i in range(1, 11)]
print(name_list)
print(name_list[0])
name_list[2] = "学生3"
print(name_list)
name_list.append("学生11")
print(name_list)
del name_list[0]
列表案例操作
from random import randint
score_list = [randint(10, 100) for _ in range(10)]
print(score_list)
maxGrade = score_list[0]
for score in score_list:
if score > maxGrade:
maxGrade = score
print(f"最高成绩是{maxGrade}分")
total_score = 0
for score in score_list:
total_score += score
mean_score = total_score/len(score_list)
print(f"平均成绩{mean_score}")
jige_list = []
for score in score_list:
if score >= 60:
jige_list.append(score)
print(jige_list)
元组
t = (122, 333, 44, 'aa')
print(t)
print(type(t))
print(t[0])
ls = [i for i in range(10)]
print(ls)
print(tuple(ls))
print(list(tuple(ls)))
字典
info = {'name': 'eric', 'age': 19, 'scores': [66, 77, 88]}
info1 = {'name': 'bob', 'age': 19, 'scores': [66, 77, 88]}
info2 = {'name': '小明', 'age': 19, 'scores': [66, 77, 88]}
print(info)
print(type(info))
print(info['name'])
print(info['age'])
print(info['scores'])
info['name'] = "艾瑞克"
print(info)
info['addr'] = "铁岭的"
print(info)
del info['scores']
print(info)
stu_list = [info, info1, info2]
print(stu_list)
|