python中hex,oct,chr,ord函数讲解

版权声明:欢迎转载,标明出处 https://blog.csdn.net/qq_24918869/article/details/52176196

hex()

中文说明:

转换一个整数对象为十六进制的字符串表示


英文说明

hex(...)
    hex(number) -> string
    
    Return the hexadecimal representation of an integer.
    
       >>> hex(3735928559)
       '0xdeadbeef'

代码演示


oct()

中文说明:

返回一个整数的八进制表示。


英文说明

oct(...)
    oct(number) -> string
    
    Return the octal representation of an integer.
    
       >>> oct(342391)
       '0o1234567'

代码演示:



chr(i)

中文说明:

返回整数i对应的ASCII字符。与ord()作用相反。

参数x:取值范围[0, 255]之间的正数。

版本:该函数在python2和python3各个版本中都可用。不存在兼容性问题。

英文说明:

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().

代码演示:



ord(i)

看上chr(i)函数

代码演示:


猜你喜欢

转载自blog.csdn.net/qq_24918869/article/details/52176196