An int function can
(1) Converting a numeric string into an integer that conforms to a mathematical format
(2) Convert floating-point numbers to integers, but simply rounding, not rounded.
Example:
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
Ten print EE
11
The float function converts integers and strings into floating-point numbers.
Example:
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
Ten print EE
The STR function converts numbers into characters
Example:
1 AA = str (123.4) #Correct
2 print AA #result = ' 123.4 '
3 BB = str ( -124.a) #SyntaxError: Invalid syntax
4 Print BB
5 cc = str (" -123.45") #correct
6 print cc #result = '-123.45 '
7 dd = str (' DDD ') #correct
8 print dd #result = DDD
9 ee = str ( -124.3) #correct
Ten print ee #result = 124.3
★★★★[Reprint]python Study Note one: Data type conversion ★★★★