operation

1) Ternary operation

  a,b,c = 2,3,4

  d = a if a>b else c

2) base

  • binary, 01
  • octal, 01234567
  • decimal, 0123456789
  • Hexadecimal, 0123456789ABCDEF binary to hexadecimal conversion     http://jingyan.baidu.com/album/47a29f24292608c0142399cb.html?picindex=1

3) Binary to string decoding, network transmission can only binary encode strings

  '&&&20'.encode(encoding = "utf-8")

  b'\x82xe2.decode(encoding="utf-8")

4) List operation - in the system it is the memory pointer

  names=["Zhang","Li","wang","Yin‘’]

  print(names)

  print(names[1])

  print(names[0:3]) # Take the head but not the tail

  print(names[-1]) #Take the first one on the right

  print(names[-3:-1]) #same as print(names[-3:])

  names.append("Zhu") #Append list

  names.insert(1,"insert after Zhang!")

  names.pop(1) #delete 

  print(names.index("Yin")) #Query record position

  print(names.count("Yin"))  #Count 

  names.clear()  #clear the list "names"

  names.reverse() #Reverse

  names.sort() #sort

  names2 = ["1","2"]

  names.extend(names2) #merge names list to names

  names3 = names.copy() #copy

  names3[2] ="change second Record!"

 

  names4=["Zhang",["Li","wang"],"Yin‘’]

  print(names4) #Note the usage of []

 

  names[2] = "xyz"

  names2[3][0] = "test"

  print(names)

  print(names2)

 

  name5 =names #Complete the same, not a simple pointer pointing problem, open a new memory space

  print(names)

  print(names5)

  

  import copy

  names5 = copy.copy(name) #浅copy

  names5 = copy.deepcopy(name) #深copy

 

  ### Use loop to copy

  for i in names:

    print(i)

 

  print(name[0:-1:2]) #Step printing is equivalent to print(name[::2]

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325219071&siteId=291194637