filmov
tv
🐍python format function on string using curly braces👨💻 number to price tag #pythontutorial

Показать описание
This video is showing python format function example with a real life scenario using Google Colab and #jupyternotebook . We are using simple python format string with curly braces to make a number string more readable. python format string syntax with curly brackets enables us to separate the digits of number with a comma after three consecutive digits. #pythontutorialforbeginners #jupyternotebook #python3 #pythoninhindi #pythonshorts #pythonprogramming #googlecolab
How to use python format function?
• The python python syntax code used in above video
number = 74829903741
number = '{:,d}'.format(number)
number
👉Output: '74, 829, 903, 741'
• To get the number as Price Tag or Currency amount
number = 74829903741
number = '$ {:,d}'.format(number) #dollar
number
👉Output: '$74, 829, 903, 741'
This improves the way numbers are written on price tags and bank account statements. So if we write 24356674209 as 24,356,674,209 can be read effortlessly when attached to certain thing or in some books or newspapers.
In our day to day life we see numbers as exactly mentioned above eg. 24,356,674,209. If it's money then the number might be appended to some currency symbol like $ 24,356,674,209 or if it's some physical quantity then it could be 24,356,674,209 m/s like this with some unit at the end. This can be achieved with python in very easy way.
python format function can be use to add 2 decimal places along with the several other implementations in various use-cases. Some of the use-cases of how to format decimals in python are mentioned below.
1. number = '{:,f}'.format(number)
2. number = '{:,2f}'.format(number)
3. number = '$ {:,d}'.format(number)
How to use python format function?
• The python python syntax code used in above video
number = 74829903741
number = '{:,d}'.format(number)
number
👉Output: '74, 829, 903, 741'
• To get the number as Price Tag or Currency amount
number = 74829903741
number = '$ {:,d}'.format(number) #dollar
number
👉Output: '$74, 829, 903, 741'
This improves the way numbers are written on price tags and bank account statements. So if we write 24356674209 as 24,356,674,209 can be read effortlessly when attached to certain thing or in some books or newspapers.
In our day to day life we see numbers as exactly mentioned above eg. 24,356,674,209. If it's money then the number might be appended to some currency symbol like $ 24,356,674,209 or if it's some physical quantity then it could be 24,356,674,209 m/s like this with some unit at the end. This can be achieved with python in very easy way.
python format function can be use to add 2 decimal places along with the several other implementations in various use-cases. Some of the use-cases of how to format decimals in python are mentioned below.
1. number = '{:,f}'.format(number)
2. number = '{:,2f}'.format(number)
3. number = '$ {:,d}'.format(number)