Lists, tuples, dictionaries of related operations

Alternatively deletions in list # 
# a = [1,2, [6,7 ], ' small star', 'to true']
# the append additional increase in the end of the list, each time adding only one element
# a.append (8 )
# iNSERT insert can be inserted anywhere in the list, and specify the index element value
# a.insert (2, "B")

# POP deleted, a default list at the end of the element deletion, can also use an index (e.g., index element 1) deletes the specified
# a.pop (1)

# Alternatively, the assignment is equivalent to
# a [2] = 'early heart'
# Print (a)

# tuple tuple symbol ()
# 1, there may be a null set = () Note that there is only one element tuple, you need to add a comma,
# is the type of tuples, otherwise there is an element of what type, what is the overall type
# 2, tuples can contain any type of data
# 3, tuple inside the elements according to a comma-separated
# 4, a tuple which the elements have an index, the index value starting from 0
# 5, to get a single value tuples which: the element group name [index]
# Print (a [2 ])
# 6, the same slice of the tuple string operation, the name of the tuple [index head: tail index: step]
# 7, which is a tuple element does not support change CRUD), the operation is carried out only when the use of the database
# a = (1, 2, [6, 7], ' small star', 'true', (3 , 4, 5))




# Dictionary elements inside dict {} is disordered
# 1, there may be empty dictionary {} = A
# 2, the dictionary to "key on" mode to store data Key: value
#. 3, the dictionary may comprise any value of type of data
# 4, the dictionary elements to be separated according comma
# 5, the dictionary of the key must be unique

a = { "class": "python11",
"Student": 119,
"Teacher": "Girl" ,
"t_age": 20,
"Score": [99, 87.5, 66.5]}
delete # dictionary, you need to specify the value to be deleted Key
# a.pop ( "t_age")
# new dictionary, key must be original the dictionary does not have a [ "name"] = Chihuahua
# a [ "name"] = "Hua Hua"
# modify the dictionary, the equivalent of re-assignment a [ "t_age"] = 18
a [ "t_age"] = 18
print (a)

Guess you like

Origin www.cnblogs.com/www-qcdwx-com/p/11488473.html