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

前端 未结 27 3937
清歌不尽
清歌不尽 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:42

    "{0:b}".format(100) # bin: 1100100
    "{0:x}".format(100) # hex: 64
    "{0:o}".format(100) # oct: 144
    

提交回复
热议问题