Python 内建函数 - bin(x)

    xiaoxiao2021-03-25  80

    Manual直译实例 整数对象非整数对象

    Manual

    Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an__index__() method that returns an integer.

    直译

    将整数转换为二进制字符串。结果为有效的Python表达式。如果‘x’不是一个Python整数对象,就必须通过定义一个index()方法来返回一个整数。

    实例

    整数对象

    >>> bin(338) '0b101010010' >>> bin(250) '0b11111010'

    非整数对象

    >>> class soShanPao: def __index__(self): return 520 >>> shanPao = soShanPao() >>> bin(shanPao) '0b1000001000'
    转载请注明原文地址: https://ju.6miu.com/read-39110.html

    最新回复(0)