python中hex,oct,chr,ord函數講解

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)函數

代碼演示:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章