- Dictionary dict
D = {key1: VALUE1, key2: value2}
Key immutable, may be a string, a number, tuple, a list can not be
dict = { 'Name': ' Runoob', 'Age': 7, 'Class': 'First'} # create a dictionary
del dict [ 'Name'] # delete key 'the Name'
dict.clear () # empty dictionary
del dict # delete dictionary
len (dict) # length dictionary
- Set SET
Basket = { 'Apple', 'Orange', 'Apple', 'PEAR', 'Orange', 'Banana'}
Print (Basket) # demonstrated here is to re-function
{ 'orange', 'banana' , 'pear', 'apple'}
a = set(‘abracadabra’)
{‘a’, ‘r’, ‘b’, ‘c’, ‘d’}
a - b # a set A contains rather a collection of elements b are not included in
a | b # collections a or b contained all the elements of
a & b # set of a and b are included in the elements of
a ^ b # not both a and b in the element
a.add (x) # add elements
a.update (x) # Update element
a.remove (x) # remove elements, there is no error
a.discard (x) # remove elements, there is no error
len (a) # length
a.clear () # Clear
x in a #x is within in a true, false otherwise
- Conditional
does not support the switch case statement
if exp1: colon can not leak
EXC1
elif EXP2:
EXC2
elif EXP3:
exc3
the else:
EXC
-
Ternary operator
c language expression? true_statement: false_statement
Python true_statement the else expression The IF false_statement -
Loops
while condition: # Note colon
statement
not do ... while statement
for var in sequences: # Note colon
statement