Lists, tuples, dictionaries and other related commands

1. List

List can store multiple values

Statistics count the number of elements in a list 1)

2) to specify the index of the index element, if not then an error

3) reverse reverse

4) pop The subscript or index cutting element, taking the last element default, after cutting the original elements in the list disappear

5) clear clear the list of elements

6) copy to copy a list

7) sort sort

8) insert element inserted by the subscript

 

9) append the specified element into the end of the list

10) remove delete the specified element

11) extend the iterables incoming list, according to the index cycle

res = ['1','2','d','f']

res.extend('abc')

print(res)

Output:

['1', '2', 'd', 'f', 'a', 'b', 'c']

 

res = ['1','2','d','f']

res.extend(['abc','21'])

print(res)

 

Output:

['1', '2', 'd', 'f', 'abc', '21']

12) [] be the value according to the following standard, may be reassigned

 

2. tuple

The list can be modified, typically it is used to read a tuple of

Under the same elements, the list occupies more resources

 

3. collection

1) remove remove elements

2) copy copy collection

3) pop shear element

4) add an element to add

5) update to add another set of elements

6) issubset determines whether a subset

7) union and collection requirements

8) difference sets differencing

9) intersection intersection of

 

4. Dictionary {key: value}

Do not repeat the dictionary key

1) pop with shear key can not be found on the error

2) popitem manner shear key-value pairs

3) setdefault to set a default key-value pair dictionary will not change the value of the original key-value pairs in the dictionary

4) fromkeys quickly create an empty dictionary

res = {}.fromkeys(['name','age'],None)

5) update two dictionaries into one dictionary

6) items all key-value pairs print them all

   keys print all the key

   All values ​​print value

7) get to take value through key, if you fail to return None

8) [] taken by key value, the error fail to be re-assigned info. [ 'Name'] = 'Li'

 

5. Boolean

0, None, an empty whole is false (False), all the rest is true (True)

 

6. A reference counting garbage collection and

Reference count: a memory address corresponding to a house number, a memory address may correspond to a plurality of house number, a house number equivalent to a reference variable.

Garbage collection:

When the reference count is zero resource recovery

Resource recovery after the program execution is completed

 

Guess you like

Origin www.cnblogs.com/Agnostida-Trilobita/p/11018495.html