Today lecture Recap: First, stacks and queues Second, the ancestral type and built-in method Third, the typical character and built-in method IV type and a set of built-in method

Today lectures Review:

A, stacks and queues

Second, the type and the built-in method ancestral

Third, the typical character and built-in method

Fourth, a collection of built-in method and type


*************************************8

A, stacks and queues

Knowledge Point: data FIFO, LIFO data

Method: 1 for loop
2.pop () method

Second, the type and the built-in method ancestral

1. Purpose: a plurality of values ​​can be stored, when not required to change a plurality of values, in which case a more appropriate ancestral

Definition: () to define tuples, with commas to separate multiple value, which may be any type of data
which enter tuple () indicates an empty tuples, type (()), returns an ancestral type, when () when any single type of data, though
denoted membered Zug formula (), but Tpye ((single data type)) returns the original data type, the result is not returned tuples tuple. Here
diet ((single data)) in this format type

tuple (interable) returns a data obtained from the vessel tuples, interable which can store a plurality of data.

A summary of:
stored plurality of values, ordered, immutable


Built Method:
Value
1. In accordance with the index value (positive value, the reverse value, care regardless of the tail), by the index value tuple, which is not variable but can not change the
type of data
(such as: int, float, str, etc.)

2. The length
len () returns the number of data is inside

3. The members of the operation
in or not in

4. Count
tuple.count ()

5. When the same data to find a first index position
tuple.index (x, start, end) returns a duplicate of the first data to find the leftmost subscript position, there will be no error

6. cycle
for Item tuple in
Print (Item)

Third, the dictionary type

1. The use of the dictionary
record a plurality of values, each value corresponding to the key with the key value is described,

2. Define the mode:
{data}, data which a plurality of spaced apart 'key' with a comma character: 'value' value pairs, usually, key represents a character string, value can be any
represent any type of data
dictionaries do not use index corresponding data is acquired, the dictionary is disordered, but also a dictionary immutable type

3. The method used to get a dictionary?
Three kinds:
1.dic = dict (X =. 1, Y = 2, Z =. 3) Print (DIC)

= 2.userinfo [
[ 'name', '...'],
[ 'Age', 18 is],
[ 'Sex', 'MALE']
]
D = {}
for K, V in UserInfo: # K, V = [ 'name', ... ']
# Print (K, V)
D [K] = # V when the data is not in the dictionary, automatically adds
print (d)

3. # d = dict (userinfo) the cast list into dictionaries

Built Method:
Value
1. Press the key value of the village, can be kept desirable, if not given Ruoguo

Length
1.len () returns the number of key-value pairs in dict

Member operator
when 1.in or not in, determine the key key

Loop:
for Item in dict
Print (Item) # dict when printed inside the key
if you want to print value
Print (dict [Item]) # print is value value

Delete
1. dict.del (), remove the key value, if not found, an error is returned
2. dict.pop (), brackets for the key value, the corresponding value of the delete key value, and returns the result value, if not there is'll get an error from the last
beginning
being given key does not exist 3. dict.popitem (), it returns the last key data: value data

keys (), values (), items () which uses this cast, list (return data)
Note: there are differences with the previously spoken range and there Python2.X Python3.X ()
DIC = { 'name' : 'Egon', 'Age': 18 is,}
1.dic.keys () # dict_keys ([ 'name', 'Age'])
2.dic.values () # dict_values ([ 'Lihua', 18 is])
3.dic.items () # dict_items ([( 'name', 'egon'), ( 'age', 18)])


dict.get (key) strokes with the same key value data in the dictionary, if not found, returns None, else returns a key value corresponding to

dict.fromkeys (data) will be in addition to other data integer data, the each of the first data of the data can be divided into (non-overlapping) respectively, for
the key value for the dictionary


old_list.update (new_list)
the data is not added to the inside old_list dictionary old_list

dict.setdefault (key, value) dict key value not in the dictionary, then the key: value added to the dictionary returns a value,
dict.setdefault (key, value) key already exists in the dictionary is not modified, the existing return corresponding to the key value

Fourth, the set
1 Purpose: relational operators, deduplication

2. Define the mode:
{}, the multi-value separated by a comma

Note: When you define a set of empty This is the default system will be seen as a typical word.

A set of three characteristics:
1. Each value must be immutable type (int, a float, STR, tuple)
2. elements can not be repeated when there is duplication of data, it will become a five duplicate data
3 set within the element of disorder (the index does not depend on a data acquisition)

Symbols:
intersection and
union |
difference set - .difference ()
symmetric difference symmertric_difference ()
is equal ==> = <=

Built-in method:

Remove
1.set.remove (member) returns a null if not found, there will be an error
2.set.discard () returns an empty


set2.difference.update (set1) is returned before the set2 set1 the same data other than

set1.isdisjoint (set2) if there is no intersection of two sets returns True, otherwise False

# Deduplication set
# limitations
# 1, can not guarantee the order of the original data type
# 2, when a certain type of a plurality of data values contained in all immutable order to re-set by

 

Guess you like

Origin www.cnblogs.com/oldboyliuhong/p/11135052.html