Operators hash type and Python

  1. Defining a set of collection and delivery difference
  2. Common operator usage
  3. The dictionary definition dictionary get items keys pop popitem update method
  4. Three logical operation

set

Collection characteristics

Uniqueness: two identical element does not exist

Disorder: There is no index

Variability: set variable set of objects is

 

Method two definitions (unique, automatically de-emphasis)

Defined directly with braces

set () type conversion

 

 

Three operations

s1 & s2 intersection

s1 | s2 union

s1 - s2 difference set (set up, before a yes, a no post)

 

 

Collection method

increase

add (value) Sort Code Ascall

 

delete

pop () can not fill parameters, the default is removed from the first start

remove (value) Fill value to be deleted 

 

change

update (iterables, the current understanding of the sequence type) iterables add, update and

 

check

s1.isdisjoint (s2) intersect returns False, no intersection returns True

 s1.issubset (s2) determined is included in the subset: the subset

 s1.issuperset (s2) comprising determining whether superset: superset

 

 

 

dictionary

Dictionary properties

Key uniqueness: dictionary keys are unique, two identical bond is absent

Ordered: the dictionary from the beginning python3.6 ordered

Variability: dictionary objects is variable, but the dictionary keys must immutable

 

Two Defining Method

Direct definition, braces, in the form of key-value pairs

Use dict function

 

 

Modify and add

There will modify this key, it does not add

 

 

Dictionary methods

increase

copy()

setdefault ( 'name', 'xxx') has the check, if any, by

dict.fromkeys (a, b) returns the new dictionary a: the sequence elements do a dictionary key b: The initial values ​​of all keys, default None

 

delete

POP ( "key") that is generally used, delete the corresponding data according to the key

 popitem () to delete the last

 clear () empty dictionary

 

change

update ({key: value}) would have to modify the key, it is not added, and DI [key] = value is the same effect

 

check

get (key) according to a corresponding key check value

 keys () to query all of the key

values ​​() query all values

items () to query all key-value pairs, the return list, you can take out an iterative

 

 

 

Logical Operators

View Object Types

type(object)

isinstance (object, object type)

 

Comparison Operators

== equal! = Not equal to> greater than <less than> = Greater than or equal to <= Less than or equal

 

If there are multiple conditions

And: and at the same time is true, the result was true

Or: or there is true, the result is true

Non-: not negated value

 

 

 

Operators in Python

Exponentiation: **

Arithmetic operators: + - * /%

Comparison operators:> <> = <= == =!

Assignment operators: + = = - = = * / ** =% = = = //

Logical operators: not and or

Member operator: in not in

Operator Identity: it is is not according to the memory address to determine

 

Guess you like

Origin www.cnblogs.com/jiyu-hlzy/p/11745221.html