**Python output integer method: **
First use the str() function to convert the number into a string and assign it to the variable i, and then use the "if i.count('.') == 0" statement to determine whether there is no decimal point in the string, and if so, output the string. So the output numbers are all integers
The sample code is as follows:
x =[23.5,45.6,987,698,123,654]for i in x:
i =str(i)if i.count('.')==0:print(I)
The results are as follows:
Example extension:
Python decimal integer output
f =1.6print("1.6 Direct integer output is%d"%f,end="\n")print("1.6Using the precision range output of floating point numbers%.0f"%f)
Output
1.6 Direct integer output is 1
1.6 Output 2 using the precision range of floating point numbers
It directly becomes an integer output, and the mantissa is directly discarded.
The accuracy display is rounded.
The above is the details of how Python outputs integers. For more information about Python output integer example methods, please pay attention to other related articles on ZaLou.Cn!
Recommended Posts