python实现基本进制转换的方法

yipeiwu_com5年前Python基础

本文实例讲述了python基本进制转换的方法。分享给大家供大家参考。具体如下:

# Parsing string with base into a number is easy
num = int(str, radix)
# We have to write our own function for outputting to string with arbitrary base
def itoa(num, radix):
 result = "" 
 while num > 0:
  result = "0123456789abcdefghijklmnopqrstuvwxyz"[num % radix] + result
  num /= radix
 return result

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python的文件操作方法汇总

文件的读操作 示例: print("->文件句柄的获取,读操作:") f = open('无题','r',encoding='utf8') d = f.read()...

python去掉字符串中重复字符的方法

复制代码 代码如下:If order does not matter, you can use "".join(set(foo))set() will create a set of u...

Python利用QQ邮箱发送邮件的实现方法(分享)

废话不多说,直接上代码 Python2.7 #!/usr/bin/env python2.7 # -*- coding=utf-8 -*- import smtplib from...

Python进行数据提取的方法总结

Python进行数据提取的方法总结

准备工作 首先是准备工作,导入需要使用的库,读取并创建数据表取名为loandata。 import numpy as np import pandas as pd loandata...

python执行使用shell命令方法分享

1. os.system(shell_command) 直接在终端输出执行结果,返回执行状态0,1 此函数会启动子进程,在子进程中执行command,并返回command命令执行完毕后的...