table of Contents
7.18 part of the container built-in method of learning
dictionary
Role: value too easy to keep a list, use a dictionary to take trouble
Defined method:
dic = {
'name':'nick',
'height':180,
'weight':140,
'hobby_list':['read','run','music','fishing','programming','coding','debugging']
}
for k,v in dic():
print(k,v)
eg: basic use:
wzh = {'name':'wangzhihui','age':18,'sex':'nan','height':201,'hobby':['sing','dance','rap','basketball']}
print(wzh.get('hobby')[3])
print(wzh['name'])
print(wzh.items()) ## 获取键值对
print(wzh.keys()) ## 获取关键字
print(wzh.values()) ## 获取值
Dictionary part built-in method
method
- Priority grasp
- Key Value
- length
- keys/values/items
- for loop
- Member operator
- Need to know
- pop: Removing elements
- fromkeys: generating a list of a dictionary, the default value None
- setdefault: There does not change the specified key value; no specified key value is changed
- get: Gets a value by key, no key default fetch None
- update: Extended Dictionary
- del: delete key-value pairs dictionary
- Priority grasp
- Value of a plurality of values or: a plurality of values
- Ordered or disordered: disordered
Variable or immutable: variable
List
Is defined by: a plurality of spaced apart elements of any data type comma in []
friends_list = ['longzeluola','canglaoshi','qiaobenai','nick']
lis = list('abcd')
A list of built-in method
- method:
- Priority grasp
- Index value (in turn can take change)
- slice
- length
- append
- Member operator
- for loop
- Need to know
- count: Count the number of elements
- remove: remove elements
- reverse: reverse list
- pop: Removing elements
- insert: insert elements
- sort: sort the list
- index: Index element
- del: remove elements
- extend: an extended list
- clear: Clears the list
- Priority grasp
- Value of a plurality of values or: a plurality of values
- Ordered or disordered: Ordered
- Variable or immutable: variable
Tuple
- Role: similar to the list, you can not keep taking
- Defined method:
friends_tuple = ('longzeluola','canglaoshi','qiaobenai','nick')
tup = tuple('abcd')
Built-in methods tuple
- method
- Priority grasp
- Index values (can not be changed)
- slice
- length
- Member operator
- for loop
- count: Count the number of elements
- index: the index element position
- Priority grasp
- Value of a plurality of values or: a plurality of values
- Ordered or disordered: Ordered
- Variable or immutable: immutable variable that says no
set
- Action: a plurality of stored values to be set between the operation
- Defined method:
s1 = {'nick','wuhao','rocky','owen','all is dsb','right'}
s1.add('nmsl')
s1.discard('right')
print(s1)
A collection of built-in method
- method:
- Priority grasp
- Deduplication
- Union |
- Intersection &
- Difference set -
- Symmetric difference ^
- Superset> emsp &;> =
- 子集 <&emsp;<=
==
- Need to know
- add: add an element
- difference_update: update the elements of the collection not
- isdisjoint: If the two elements of the intersection is empty return True, otherwise False
- remove: Removes the element does not exist error value #
- discard: remove elements not being given #
- Priority grasp
- Value of a plurality of values or: a plurality of values
- Ordered or disordered: disordered
- Variable or immutable: variable