A set of relational operators

Summary of five data types:

Distinguished by the number of storage:

Memory can store a value - number, string

Container type, a plurality of stored value - a list of tuples, dictionaries

At the variable immutable distinguished:

Variable - lists, dictionaries

Immutable - number, a string, a tuple, the tuple

Access order to distinguish between:

--- direct access to digital

Sequential access (access press superscript) - strings, lists, tuples

Access key value - dictionary

Collection: different elements, born to heavy

a = {1,2,3,4,5}

b={2,3}

Intersection

print(a & b)

print(a.intersection(b))

Union

print(a | b)

print(a.union(b))

Difference set

 

print(a - b)

print(a.difference(b))

Symmetric difference

print(a ^ b)

The relational operators: a whole with another operation between the overall

Built-in methods for the collection:

1. Update

s1 = {1,2,3}
s2= {'p'} s1.update (
' quit ' ) - Update the increase quit separated into the collection
s1.update (s2) - s1 s2 is updated to the inside

2. Increase

s1 = {1,2,3}
s1.add ( 'quit') - will increase as the string quit

  

3. Delete

Random deleted

a = {1,2,3,4,5}
a.pop()  

 Specifies to delete

a = {1,2,3,4,5}
a.remove (1) # delete the specified number or character, will delete the error does not exist, an error will be empty 

a.discard (7) # delete does not exist without error

4. Clear

a = {1,2,3,4,5}
a.clear()

 

  

Guess you like

Origin www.cnblogs.com/cdm023/p/11894378.html