1. <source id="nejs2"></source>
  2. <video id="nejs2"></video>
    <source id="nejs2"></source>
          1. Python hex()

            更新:

            hex()函數有助于將給定的數字轉換為相應的十六進制字符串格式。返回的十六進制字符串的前綴必須為“0x”。

             **hex(number)** #Where number shows a integer number 
            

            十六進制()參數:

            只接受一個參數。如果我們將一個對象作為參數傳遞給hex()函數,該對象必須定義返回整數的 __index__()函數。

            參數 描述 必需/可選
            目標 int 對象,或者它必須定義一個返回整數的__index__()方法 可選擇的
            整數 可以是任何基數,如二進制、八進制等 可選擇的

            十六進制()返回值

            要獲得浮點數的十六進制表示,需要使用float.hex()方法。

            | 投入 | 返回值 | | 整數 | 十六進制格式 | | 漂浮物 | 十六進制格式 | | 目標 | 十六進制格式 |

            Python 中hex()方法的示例

            示例hex()是如何工作的?

             number = 435
            print(number, 'in hex =', hex(number))
            
            number = 0
            print(number, 'in hex =', hex(number))
            
            number = -34
            print(number, 'in hex =', hex(number))
            
            returnType = type(hex(number))
            print('Return type from hex() is', returnType) 
            

            輸出:

            435 in hex = 0x1b3
            0 in hex = 0x0
            -34 in hex = -0x22
            Return type from hex() is <class></class> 

            示例 2:浮點數的十六進制表示

             number = 2.5
            print(number, 'in hex =', float.hex(number))
            
            number = 0.0
            print(number, 'in hex =', float.hex(number))
            
            number = 10.5
            print(number, 'in hex =', float.hex(number)) 
            

            輸出:

            2.5 in hex = 0x1.4000000000000p+1
            0.0 in hex = 0x0.0p+0
            10.5 in hex = 0x1.5000000000000p+3 

            示例hex()如何處理對象?

             class Data:
                id = 0
            
                def __index__(self):
                    print('__index__ function called')
                    return self.id
            
            d = Data()
            d.id = 100
            
            print(hex(d)) 
            

            輸出:

            __index__ function called
            0x64 
            頂部 久久久久99精品成人片毛片_黃色A片三級三級三級无码_日本不卡高清视频v中文字幕_高清欧美视频一区二区
            1. <source id="nejs2"></source>
            2. <video id="nejs2"></video>
              <source id="nejs2"></source>