Meta-group
If there is only one data in the tuple, and there is no comma, the tuple is the same as the data type of the data inside.
# Tu = ("Alex") #class strtu = (1) # class int# tu = (True) #class boolprint(Type (TU))
List
The list can be added between the list
L1 = [== ['Alex','wusir'= L1 + L2 Print(L3) #[1, 2, 3, ' Alex ', ' Wusir ']
Note: When looping a list, dictionaries , it is best not to change the size of this list (additions and deletions) of the operation
Trap Question 1
#Delete data that is indexed as odd in the L1 listL1 = [11, 22, 33, 44, 55, 66, 77, 88]#method All slices plus step#del L1[::2]## Print (L1)#method Two backwards Delete#for I in range (len (L1), -1,-1):#if I%2 = = 1:#del L1[i]#print (L1)#method Three directly moves an even number out to the new list#L2 = list ()#For i in range (len (L1)-1):#if I% 2 = = 0:#l2.append (L1[i])#print (L2)
Quickly create a dictionary Fromkeys
DIC = Dict.fromkeys ([1,2,3],{"Alex"})print(DIC) # {1: {' Alex '}, 2: {' Alex '}, 3: {' Alex '}}
Interview question: How to create a dictionary
1) dic = {}
2) dic = Dict ()
3) dic = Dict.fromkey (key, value) #如果没有值, default is None
Trap question Two
Dic1 = Dict.fromkeys ([],[])print(dic1) dic1[1].append ('Alex ')print(dic1) #print(ID (dic1[1))) Print(ID (dic1[2)))print(ID (dic1[3)))
Conversion of data types
int STR BOOL Three conversions
str <---> bytes
STR <---> list
Dict.keys () dict.values () dict.items () list ()
Tuple <---> list
Dict---> List
string conversion to list split
# str---> List
# S1 = ' Alex Wusir taibai '
# L1 = S1.split ()
# print (L1)
# list ---> str the elements in this list are all str types
Convert list to String jion
# L1 = [' Alex ', ' Wusir ', ' Taibai ', 100]
# # s2 = '. Join (L1)
# # print (S2)
Knight Plan-python full stack 07 base data type Supplement