“Formatação de saída mais sofisticada em python” Respostas de código

Formatação de saída mais sofisticada em python

>>> yes_votes = 42_572_654
>>> no_votes = 43_132_495
>>> percentage = yes_votes / (yes_votes + no_votes)
>>> '{:-9} YES votes  {:2.2%}'.format(yes_votes, percentage)
' 42572654 YES votes  49.67%'
Shy Skunk

Formatação de saída mais sofisticada em python

>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
>>> for name, phone in table.items():
...     print(f'{name:10} ==> {phone:10d}')
...
Sjoerd     ==>       4127
Jack       ==>       4098
Dcab       ==>       7678
Shy Skunk

Formatação de saída mais sofisticada em python

>>> year = 2016
>>> event = 'Referendum'
>>> f'Results of the {year} {event}'
'Results of the 2016 Referendum'
Shy Skunk

Formatação de saída mais sofisticada em python

>>> animals = 'eels'
>>> print(f'My hovercraft is full of {animals}.')
My hovercraft is full of eels.
>>> print(f'My hovercraft is full of {animals!r}.')
My hovercraft is full of 'eels'.
Shy Skunk

Formatação de saída mais sofisticada em python

>>> import math
>>> print(f'The value of pi is approximately {math.pi:.3f}.')
The value of pi is approximately 3.142.
Shy Skunk

Respostas semelhantes a “Formatação de saída mais sofisticada em python”

Perguntas semelhantes a “Formatação de saída mais sofisticada em python”

Mais respostas relacionadas para “Formatação de saída mais sofisticada em python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código