How to convert an integer to a string in any base?

前端 未结 27 3936
清歌不尽
清歌不尽 2020-11-22 02:25

Python allows easy creation of an integer from a string of a given base via

int(str, base). 

I want to perform the inverse: creati

27条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 02:51

    >>> numpy.base_repr(10, base=3)
    101
    

    Note that numpy.base_repr() has a limit of 36 as its base. Otherwise it throws a ValueError

提交回复
热议问题