environment windows7 (I want a Mac Book Pro 16inch) Visual Studio Code chrome python ver3.8.3
This article is written for beginners in programming and Python.
int
、float
Type conversion of numbers (integers) and decimal points (floating point numbers)
Number (integer) ・ ・ ・ ʻint () Decimal point (floating point number) ・ ・ ・
float ()`
I will do it at.
style.py
print("123" * 3)
#123123123
print(int("123") * 3)
#369
print("123" * 3)
↑ outputs the character (character string) 123 repeatedly three times.
print(int("123") * 3)
However, if ʻint () is used, the number will be calculated with
369` in the solution of the formula.
type.py
print("3.9" * 3)
# 3.93.93.9
print(float("3.9") * 3)
#11.7
print("3.9" * 3)
This also outputs the character (character string) repeatedly three times.
print(float("3.9") * 3)
If you set it to float ()
in this way, it will be calculated between the numbers and 11.7
of the solution of the formula.
Then what if the floating point number is ʻint ()`?
style.py
print(int(3.94649))
print(type(int(3.9)))
Let's write it like this. Then
style.py
print(int(3.94649))
#3
print(type(int(3.9)))
#<class 'int'>
Then The decimal point (floating point number) is now a number (integer).
In actual coding I see str
occasionally, but I haven't seen ʻint or
float` yet.
How is it used in the actual field and how often is it?
I'm interested. Even if you learn, if you are a rare character, the tension will drop.
That's all for how to convert type: ʻint` and'float'.
Recommended Posts