python类型转换

1.数字转字符串

  str(42) == "42"

2.字符串转数字

  int("42") == 42

3.字符转ascii码

  ord("a") == 97

4.ascii码转字符

  chr(97) = "a"

5.二、八、十六进制转十

  int("11",2) == 3

  int("77",8) == 63

  int("aa",16) == 170

6.十进制转二、八、十六

  bin(4) == "0b100"

  oct(77) == "0115"

  hex(16) == "0x10"

  

原文地址:https://www.cnblogs.com/heitan/p/6242490.html