#coding:utf-8
def translate(st="你要转换的字符串"):
try:
num=int(st)
return num
except:
#print "\"%s\" is not an integer."%st
pass
try:
num=float(st)
return num
except:
#print "\"%s\" is not a float."%st
pass
try:
num=complex(st)
return num
except:
#print "\"%s\" is not a float."%st
pass
return st #返回原串表示转换失败
温馨提示:答案为网友推荐,仅供参考