Data type: list, tuple, collection, dictionary
#列表 (indicated in brackets)
students=[" Xiao Ming", "Xiao Hong", " Xiaoice", "Xiao Yue"," little White"]
Print students[3]
Students[3]= " Lei Feng". # # Change The value of 3
Print students[3]
#元组
Students= ("Xiao Ming", "Xiao Hong", "Xiaoice", "Xiao Yue", "Xiao Bai")
Print students[1]
The difference between a list and a tuple
1, the value of the elements of the list can be modified, and the value of the elements inside the tuple cannot be modified to read only
2, the symbol of the list is [], and the tuple's symbol is ().
#集合
Function
1. Establishing a relationship
2. Eliminate duplicate elements
The format of the collection is:set (Element)
Cases:
A=set("ABCDEFG")
B=set("CDFM")
#交集
X=a&b
Print X
#并集
Y=a|b
#差集
Z=a-b
#去重复元素
New=set(a) # Remove duplicate values of a
#字典
Also called associative array, enclosed in curly braces {}.
zidian={' name':' xiaoming', ' Home':' Shenzhen ', ' like':' music'}
In fact, the dictionary contains a whole thing, each has specific information, such as the name,home, likethe values are xiaoming,Shenzhen,Music, elements separated by commas
Cases:
k={"name": " xiaoming", "Home": " Shenzhen"}
Print k["name"]
#添加字典里面的项目
k["like"]= "Music"
Print k["Name"]
Print k["Like"]
Python data type