Telegram Group & Telegram Channel
Форматирование чисел в f-строках

Начиная с версии Python 3.6, стали доступны f-строки. Это удобный способ форматирования текста. Но не все знают, что он умеет вставлять float числа с настраиваемым количеством знаков после запятой.

Допустим у нас есть float число pi = 3.14159265359. Если мы его просто скорвертируем в строку, то она примет следующий вид:

>>> str(3.14159265359)
'3.14159265359'


Но что если важно выписать только до сотых долей? Делается это черех f-строку:

>>> f'Число Пи это {pi:.2f}'
'Число Пи это 3.14'


После обьявления имени переменной мы вставляем следующую комбинацию: .2f, где цифра как раз и указывает, сколько знаков после запятой нужно преобразовать в строку. Более подробно это описано в PEP 498.

#fstring



tg-me.com/python_academy/771
Create:
Last Update:

Форматирование чисел в f-строках

Начиная с версии Python 3.6, стали доступны f-строки. Это удобный способ форматирования текста. Но не все знают, что он умеет вставлять float числа с настраиваемым количеством знаков после запятой.

Допустим у нас есть float число pi = 3.14159265359. Если мы его просто скорвертируем в строку, то она примет следующий вид:

>>> str(3.14159265359)
'3.14159265359'


Но что если важно выписать только до сотых долей? Делается это черех f-строку:

>>> f'Число Пи это {pi:.2f}'
'Число Пи это 3.14'


После обьявления имени переменной мы вставляем следующую комбинацию: .2f, где цифра как раз и указывает, сколько знаков после запятой нужно преобразовать в строку. Более подробно это описано в PEP 498.

#fstring

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/771

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

Telegram Be The Next Best SPAC

I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. I’m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegram’s pre-initial coin offering (ICO) tokens. “If Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,” he says.

Python Academy from es


Telegram Python Academy
FROM USA