在繼列表的學習之后,進行了元組的學習。元組和列表功能相似,只是元組不能進行修改,所以元組又叫只讀列表。
下面列舉的是一系列的字符串操作:
name.capitalize()? #首字母大寫
name.count("a")?? #數列表中有幾個a
name.center(5o,"-")? #意思是一共打印50個字符,不夠用“-”補
name.endswith("ex") #看字符串是否以ex結尾
name.expandtabs(tabsize=30)?? #將tab鍵轉換成30個空格
下面學習的是字典:
在字典中不是通過位置進行索引的,字典是無序的,因為其無下標,字典不需要下標,因為其有key
info={
????? 'stu1101':"A"
????? 'stu1102':"B"
????? 'stu1103':"C"
}
print(info)
(1)查
法1):print(info["stu1101"])?? #通過鍵查找
法2):print(info.get('stu1103'))
(2)改
info["stu1101"]="wu"
(3)增
info["stu1104"]="c"
(4)刪
1)法1:del info["stu1101"]
2)法2:info.pop("stu1101")
#判斷一個字典中有沒有
print('stu1104' in info)
#多級字典的嵌套
catalog={
" "={
"key":[list]
}
'
" "={
}
}
info.value()? #打印值
info.key()? #打印鍵
?