1 aa = int("124") #Correct
2 print "aa = ", aa #result=124
3 bb = int(123.45) #correct
4 print "bb = ", bb #result=123
5 cc = int("-123.45") #Error,Can't Convert to int
6 print "cc = ",cc
7 dd = int("34a") #Error,Can't Convert to int
8 print "dd = ",dd
9 ee = int("12.3") #Error,Can't Convert to int
10 print ee
11
二、float函数将整数和字符串转换成浮点数。
1 aa = float("124") #Correct
2 print "aa = ", aa #result = 124.0
3 bb = float("123.45") #Correct
4 print "bb = ", bb #result = 123.45
5 cc = float(-123.6) #Correct
6 print "cc = ",cc #result = -123.6
7 dd = float("-123.34") #Correct
8 print "dd = ",dd #result = -123.34
9 ee = float('123v') #Error,Can't Convert to float
10 print ee