python- data type (lower)

byte:

msg = 'I Love Beijing Tiananmen'
Print (msg.encode (encoding = 'UTF-8'). decode (encoding = 'UTF-8'))

Turn into a byte string, to turn back

 

 

List:

names = [ "Zhangyang", "Guyun", "XiangPeng", "XuLiangChen"]
Print (names)
Print (names [0], names [2])
Print (names [. 1:. 3]) # slicing, care regardless tail does not comprise a third
print (names [-1]) # number from the right
print (names [-3:]) # fetch the next three
print (names [-3: -1] ) # 2 takes an intermediate
print (names [: 3]) # 0 can be omitted

= names [ "Zhangyang", "Guyun", "XiangPeng", "XuLiangChen"]
names.append ( "LeiHaiDong") # appends
names.insert (1, "ChenZhongHua") # inserted into a location
names [2] = "XieDi" # change
names.remove ( "ChenZhongHua") # delete
del names [1] # delete a location
names.pop () # delete the last
names.pop (1) # delete a location
print (names)

= names [ "Zhangyang", "Guyun", "XiangPeng", "ChengRongHua", "XuLiangChen"]
Print (names)
Print (names.index ( "Guyun")) # "Guyun" position
print (names [names. index ( "Guyun")])
Print (names.count ( "ChengRongHua")) # count the number of
names.clear () # clear the list of elements in the
print (names)
names.reverse () # reverse
print (names)

names.sort () # sort order ascii code
Print (names)
names2 = [1,2,3,4]
names.extend (names2)
print (names, names2)
del names2 # remove elements
print (names, names2 )


= names [ "Zhangyang", "Guyun", "XiangPeng", [ "Alex", "Jack"], "ChengRongHua", "XuLiangChen"]
NAME2 = names.copy () # Copy
Print (names)
Print (NAME2)
names [2] = "Peng to"
Print (names)
Print (NAME2) # same
names [. 3] [0] = "Alex"
Print (names)
Print (NAME2) # becomes
name2 = names #names change list content . name2 also changed

import copy
names = ["ZhangYang","Guyun","XiangPeng",["Alex","Jack"],"ChengRongHua","XuLiangChen"]
name2 = copy.copy(names) #浅copy ,与name2 = names.copy()效果一样

Other shallow copy

person = ['name',['a',100]]
p1 = person[:]
p2 = list(person)

import copy
names = ["ZhangYang","Guyun","XiangPeng",["Alex","Jack"],"ChengRongHua","XuLiangChen"]
name2 = copy.deepcopy(names) #深copy
print(names)
print(name2)
names[2] = "向鹏"
print(names)
print(name2) #不变
names[3][0] = "alex"
print(names)
print(name2) #不变

Tuple
tuple fact, with a list of almost as well as keep a set of numbers, but once it is created, it can not be modified, so called read-only list
names = ( "alex", " jack", "eric")
it is only two a method, one count, one index

Set operations

air

Guess you like

Origin www.cnblogs.com/peiya/p/11969657.html