Lists List
[Vale,...] Can be added to any type of data, and can be nested, indefinite length
Student = ["Beimenchuixue", "Mayun", "Mahuiteng", "naichadong"]product = ["blog", "TaoBao", "Weichat", "JD"]score = ["Beim Enchuixue ", [90, 80, 66, 77, 99]
List Access
1. Specify insert. insert
2. Insert at the end. Append
3. Value deletion. Remove
4. Know the index to delete and return the value. Popdel
5. Clear the list. Clear
6. Reverse the list. Reverse
7. Sorted list. sort
8. List of extensions. Extend
9. Copy the list. Copy
10. Indexed Index
11. Define an empty list [] list ()
Product = ["Bokeyuan", "TaoBao", "Weichat", "JD", "Baiduyun", "Aliyun"]product.insert (1, "Jinritoutiao") print (product) Product.append ("Douyin") print (product) product.remove ("JD") print (product) del_product = Product.pop (0) print (DEL_ Product) print (product) Product.reverse () print (product) # Product.sort (Lambda x:x[0],) # print (product) two_product = [" Weiruan "," Centos "," Nginx "]product.extend (two_product) print (product) copy_product = Product.copy () print (Copy_ Product) Print (Copy_product.index ("Aliyun")) Copy_product.clear () print (copy_product) empty_list = []empty_list_two = List () print (empty_list, empty_list_two) print (Product.count ("Aliyun")) Tuple_product = ("Bokeyuan", "TaoBao", " Weichat "," JD "," Baiduyun "," Aliyun ") Print (Tuple_product.index (" Weichat ")) Print (Tuple_product.count (" Weichat "))
Tuple tuples
(Value, ...)
1. Declaring data immutable, avoiding hidden errors, fixed data recommendations using tuples
2. Can add any type of data, and can be nested, a single value needs to be added,
3. Define empty tuple () tuple ()
Tuple_product = ("Bokeyuan", "TaoBao", "Weichat", "JD", "Baiduyun", "Aliyun") Print (Tuple_product.index ("Weichat")) Print (Tuple_product.count ("Weichat"))
The meaning of ()
1. Forcing or emphasizing priority order
2. Mathematical Operation type ((5)) result is int
3. Empty tuples () and tuples (value, ...)
4. Generator () + for
5. The regular expression is treated as a character and takes its matching character (re)
result = Not True or Trueresult_two = Not (True or true) print (result, result_two) print (Type ((6 + 7)) Print (Type (())) genera Tor = (I for I in range) print (generator.__next__ ()) One_str = "Simple is better than complex." Regular = r "\w+" Import refind_list = Re.findall (regular, one_str) print (find_list)
python-List tuple-list tuple