转字符 str()

  1. a = 10
  2. res = str(a)
  3. # '10'

转数字 int()

  1. a = "520"
  2. b = int(a)
  3. # 520
  4. a = 520.99
  5. b = int(a)
  6. # 520

转浮点数 float()

  1. a = "520"
  2. b = float(a)
  3. # 520.0
  4. a = 520
  5. b = float(a)
  6. # 520.0

字符转数组 list()

  1. temp = 'nihaoshijie'
  2. temp = list(temp)
  3. # 打印 ['n', 'i', 'h', 'a', 'o', 's', 'h', 'i', 'j', 'i', 'e']

元祖转数组 list()

  1. temp = (1,2,3,4,5,6)
  2. temp = list(temp)
  3. # 打印 [1, 2, 3, 4, 5, 6]