Here are some examples on working with numbers.
Data types for numbers
In python there are three different datas available for handling numbers
Converting from string
When working with numbers, a typical thing to do is to create them from string values:
Convert from string to int
Convert from string to float
Convert from string to Decimal
Decimals are handled slightly differently as compared to int
and float
.
To use Decimals, the following imports are needed:
…now it is possible to create a Decimal from a string value:
There are numerous alternatives when it comes to formatting numbers. Some are listed below:
Further resources
My python challenge