python类型转换

时间:2021-02-21 23:17:32

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"