這篇文章主要介紹了python實現基本進制轉換的方法,涉及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程序設計有所幫助。
新聞熱點
疑難解答