1. List: list, each element of the list are separated by a comma, the list elements may be numbers, strings, lists, tuples, like Boolean
li = [11,'kdjf',['fklj'],('jfklj'),True]
2.list can access, modify and delete the list of values by indexing and slicing:
v1 = [2] v2 = [1: 3] print (v1, v2) [2] = 'jflkjfd' del [4] print () results: {k1 '': 123, 'k2': 123, 'K3': 123} kobzl [ ''] [ 'cruiser' kobzl, [ '']] , [11 'cruiser', 'jflkjfd', '' jfklj]
3.in elements used to determine (to distinguish a comma) is in the list if false otherwise return True
li = [11,'kdjf',['fklj',3333],('jfklj'),True] v1 =11 in li v2 = 3333 in li v3 =['fklj',3333]in li print(v1,v2,v3) 结果是 True False True
To convert a string to a list just use list (str variable names), but the list into a string: 1. If all the string you can use the join method 2 if there is a string of numbers both a method for using the loop will have to be carried out:
li =['fkj','klfj','jfkl','fkdj'] v1 = ''.join(li) lis = ['jfklj','jfklj',12344,'jfklj'] st ='' for i in lis : st+= str(i) print(v1,st) 结果是: fkjklfjjfklfkdj j fkljjfklj12344jfklj
1. The list of black magic append an element is added at the end (the brackets directly into the content list), clear the list is empty the list becomes an empty list, copy is shallow copy, count is the number of the list contains few concrete the two elements:
lie = ['jfkljf','ddk','jfklj',112,'ddk'] lie.append('fjkljf') lie.append(['jfklj',333]) print(lie) v1 =lie.count('ddk') lie.clear() print(lie,v1) 结果是 {'k1': 123, 'k2': 123, 'k3': 123} ['jfkljf', 'ddk', 'jfklj', 112, 'ddk', 'fjkljf', ['jfklj', 333]] [] 2
2. The list of black magic: index if the index is returned if it is not an error is reported, insert insert elements to the list, reserve list will be reversed, sort will sort the list either :( sort all digital, or all the characters otherwise it will error): remove out of elements in the list
lie = [ 'jfkljf', 'ddk', 'jfklj', 112, 'ddk'] v1 = lie.index (112) # v2 = lie.index ( 'fklj') lie.insert (1, 'jfkj') print (v1, lie) lie.reverse () print (lie) lie.remove (112) lie.sort () print (lie) lie.sort (reverse = True) print (lie) 结果是 { 'k1': 123 , 'k2' 123, 'k3': 123} 3 [ 'jfkljf', 'jfkj', 'ddk', 'jfklj', 112, 'ddk'] [ 'ddk', 112, 'jfklj', 'ddk '' jfkj ',' jfkljf '] [' ddk ',' ddk ',' jfkj ',' jfklj ',' jfkljf '] [' jfkljf ',' jfklj ',' jfkj ',' ddk 'ddk ']
3. The list is ordered, can be modified
4. The tuple is a list of secondary processing, can not be increased to modify or delete the
5. Create tuple again preferably a comma after the last tuple
7. tuple can also be accessed by an index value tuples and slicing
8. yuan a group of elements can not be modified, but the list may be modified
9. dictionary keys and values with a test composition with the intermediate: the link between each of a comma distinguished:
info = { 'k1': 'jfkj', 'jkj': 'fkj'}
10. The keys of the dictionary can be arbitrary, but is a list of keys and values can not itself dictionaries:
11. dictionaries are unordered:
To delete an item in the dictionary: del variable name [keys]
12. The loop keys and values and items:
info = {'k1':'jfkj','jkj':'fkj'} for i in info: print(i) for m in info.keys(): print(m) for n in info.values(): print(n) for h in info.items(): print(h) 接过是 k1 jkj k1 jkj jfkj fkj ('k1', 'jfkj') ('jkj', 'fkj')