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

yipeiwu_com6年前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 Tkinter模块实现时钟功能应用示例

Python Tkinter模块实现时钟功能应用示例

本文实例讲述了Python Tkinter模块实现时钟功能。分享给大家供大家参考,具体如下: 本机测试效果: 完整代码: # coding=utf-8 from Tkinter i...

python使用win32com在百度空间插入html元素示例

复制代码 代码如下:from win32com.client import DispatchEximport timeie=DispatchEx("InternetExplorer.Ap...

python中的代码编码格式转换问题

  刚来这个公司,熟悉了环境,老大就开始让我做一个迁移、修改代码的工作,我想说的是,这种工作真没劲~~,看别人的代码、改别人的代码、这里改个变量、那里改个文件名······,都是些没技术...

python requests.post带head和body的实例

如下所示: # coding = utf-8 import requests import json host = "http://47.XX.XX.XX:30000" endpo...

Python 类的继承实例详解

Python 类的继承详解 Python既然是面向对象的,当然支持类的继承,Python实现类的继承比JavaScript简单。 Parent类: class Parent:...