How to convert Python # type for Python super beginners: int, float

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.

1. How to convert Python type

intfloat 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

How to convert Python # type for Python super beginners: int, float
How to convert Python # type for Python super beginners: str
Python # How to check type and type for super beginners
Python for super beginners Python # dictionary type 2 for super beginners
Python for super beginners Python for super beginners # Easy to get angry
How to make Python faster for beginners [numpy]
Convert numpy int64 to python int
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
[For beginners] How to use say command in python!
[For beginners] How to study Python3 data analysis exam
Python #index for super beginners, slices
Python #len function for super beginners
Python #Hello World for super beginners
[For beginners] How to register a library created in Python in PyPI
[Python] How to convert db file to csv
[Python] How to convert a 2D list to a 1D list
How to convert Python to an exe file
Let's put together Python for super beginners
How to use "deque" for Python data
Memo # 4 for Python beginners to read "Detailed Python Grammar"
The fastest way for beginners to master Python
[Python] How to use two types of type ()
How to make Spigot plugin (for Java beginners)
Memo # 3 for Python beginners to read "Detailed Python Grammar"
How to install Python for pharmaceutical company researchers
Memo # 1 for Python beginners to read "Detailed Python Grammar"
How to use data analysis tools for beginners
How to convert SVG to PDF and PNG [Python]
Try to calculate RPN in Python (for beginners)
Easy understanding of Python for & arrays (for super beginners)
Memo # 2 for Python beginners to read "Detailed Python Grammar"
How to get dictionary type elements of Python 2.7
Memo # 7 for Python beginners to read "Detailed Python Grammar"
How to convert (32,32,3) to 4D tensor (1,32,32,1) with ndarray type
Convert exponential notation float to str in Python
Introduction to Programming (Python) TA Tendency for beginners
Memo # 6 for Python beginners to read "Detailed Python Grammar"
How to handle datetime type in python sqlite3
[For beginners] How to study programming Private memo
Memo # 5 for Python beginners to read "Detailed Python Grammar"
About Python external module import <For super beginners>
How to install Python
How to install python
python textbook for beginners
OpenCV for Python beginners
[BigQuery] How to use BigQuery API for Python -Table creation-
How to convert / restore a string with [] in python
How to run python in virtual space (for MacOS)
How to write a list / dictionary type of Python3
How to convert floating point numbers to binary numbers in Python
Python --Notes when converting from str type to int type
Python beginners talk about how to remember this much
How to convert JSON file to CSV file with Python Pandas
python, php, ruby How to convert decimal numbers to n-ary numbers
Convert Webpay Entity type to Dict type (recursively in Python)
Convert elements of numpy array from float to int
[Introduction to Python] How to write repetitive statements using for statements
Tips for Python beginners to use the Scikit-image example for themselves 7 How to make a module
[Python] Convert time display (str type) using "" "and"'" to seconds (float type) with datetime and timedelta