Impresión con formato usando f-strings
Duración de la lección: 3:16 min
[1]:
import math
print(f"The value of pi is approximately {math.pi:.3f}.")
The value of pi is approximately 3.142.
[2]:
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
[3]:
animals = "eels"
print(f"My hovercraft is full of {animals}.")
My hovercraft is full of eels.
[4]:
#
# !a aplica ascii()
#
print(f"My hovercraft is full of {animals!a}.")
My hovercraft is full of 'eels'.
[5]:
#
# !r aplica la función repr()
#
print(f"My hovercraft is full of {animals!r}.")
My hovercraft is full of 'eels'.