python3 int() 各數據類型轉int


print(int('0b1010',0))#二進制數
print(int('0xa',0))#十六進制數
print(int('0xa',16))
print(int('a',16))

print(int(0xa))
print(int(10.0))

"""
int(x=0) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
    
     將數字或字符串轉換為整數,如果沒有給出參數則返回0。 如果x是數字,則返回x .__ int __()。
對於浮點數字,這截斷小數為零。
如果x不是數字或者給定了base,那么x必須是一個字符串,bytes或bytearray實例,表示中的整數文字給定基數。
文字可以以''或' - '開頭,並被包圍通過空白。 基數默認為10.有效基數為0和2-36。
       基數0表示將字符串中的基數解釋為整數文字。

>>> int('0b100', base=0)
4
# (copied from class doc)
"""


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM