index=0
while index<10:
print(index)
index+=1
num=1
sum=0
while num<=100:
sum+=num
num+=1
print(sum)
num1=1
sum1=0
while num1<=10:
sum1+=num1
num1+=1
print(sum1)
a=1
b=0
c=0
i=0
while i<10:
c=a+b
a=b
b=c
i+=1
print(c)
list=["aaa","bbb","ccc","ddd"]
print(list)
print((len(list)))
print((list[-1]))
print(list[2])
修改
list[2]="dd"
print(list[2])
删除
del(list[2])
print(list)
fff="fff"
list.append("fff")
print(list)
dict={}
dice_zcy={"name":"zcy","sex":"man","city":"xy"}
print(dice_zcy)
a=dice_zcy["sex"]#打印时,创建临时变量接收
键名只能一次取一个
print(a)
dice_zcy["height"]=180
print(dice_zcy)
del dice_zcy["name"]
print(dice_zcy)
dice_zcy["sex"]="shabi"
print(dice_zcy)
squre_account_list=[
{"name":"zcy","age":"18","contury":"England","sex":"male","height":"180"},
{"name":"aaa","age":"13","contury":"china","sex":"male","height":"180"},
{"name":"bbb","age":"15","contury":"America","sex":"male","height":"180"},
{"name":"ccc","age":"19","contury":"japan","sex":"male","height":"180"},
{"name":"ddd","age":"21","contury":"England","sex":"male","height":"180"},
{"name":"fff","age":"55","contury":"England","sex":"male","height":"180"}
]
first_one=squre_account_list[0]
if first_one["name"]=="ddd" :
print(first_one)
else:
print("他不是ddd")
third_one = squre_account_list[2]
if first_one["name"]"ddd":
print(first_one)
else:
print("他不是ddd")
#遍历循环,从头到尾运行一遍,针对的是一组数据
#for循环-遍历下标-通过下标获取数据
for index in range(0,len(squre_account_list)):
person_name = squre_account_list[index]
if person_name["name"]"ddd":
print(person_name)
break
else:
print("他不是ddd")
for循环,遍历列表的值,直接取值
for item in squre_account_list:
if item["name"]=="David":
print(item)
else:
print("他不是ddd")