第一种:利用str()函数将数字转化成字符串,再利用len()函数判断位长. a=Int(raw_input("the number you want type in:") b=len(str(a)) print b 第二种:利用除10取商,通过循环次数判断位数. c=0 a=int(raw_input("the number you want type in:")) while a!=0: a=a/10 c +=1 print c
目标 想要获取一个整形数字的二进制表示 bin 内置函数 看一下官方的解释 Convert an integer number to a binary string prefixed with "0b". The result is a valid Python expression. If x is not a Python int object, it has to define an index() method that returns an integer. Some exa
#coding=utf- from struct import pack,unpack byte=pack('f',1.5) print(byte) print([i for i in byte]) byte=pack('f',123432.523424) print(byte) print([i for i in byte]) 输出 ?? ['\x00', '\x00', '\xc0', '?'] C?G ['C', '\x14', '\xf1', 'G']
1.获取小数点位数方法 a. 使用 js 中 subsrting,indexOf,parseFloat三个函数,代码如下: var s = "22.127456" ;//s 为 字符串 ,substring.indexOf 只能对字符串使用 var point = s.indexOf(".")+3;//获取小数点在字符串中的位置,并向后加3作为最后字符串结束位 var str = s.substring(0,point) ;//获取0到point之间的字符串 var
python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac(): if os.name == 'nt': try: ret = '' CmdLine = 'ipconfig /all' r = os.popen(CmdLine).read() if r: