“Formato de salida más elegante en Python” Código de respuesta

Formato de salida más elegante en 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

Formato de salida más elegante en 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

Formato de salida más elegante en Python

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

Formato de salida más elegante en 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

Formato de salida más elegante en Python

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

Respuestas similares a “Formato de salida más elegante en Python”

Preguntas similares a “Formato de salida más elegante en Python”

Más respuestas relacionadas con “Formato de salida más elegante en Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código