Python int 转其他进制(dec2other)
代码允许 int 转换为2-36之间的任何进制{:10_316:}map='0123456789abcdefghijklmnopqrstuvwxyz'def dec2other(num,/,base):
if not isinstance(num,int)or base<2 or base>36:
raise ValueError("dec2other() base must be an integer >= 2 and <= 36")
if num<0:
re=True
num=-num
else:
re=False
res=''
while num:
res=map+res
num//=base
if res:
if re:
return '-'+res
return res
return '0'如果代码有问题,欢迎在评论区指正!{:10_323:} 自占二楼
页:
[1]