Or nested f-strings in python 3.6
In [4]:
l = [x**.5 for x in range(1, 11)]
print('Default:', l)
In [5]:
s = ', '.join(map(lambda x: f"{x:.3f}", l))
print(f'Their floats: [{s}]')
In [6]:
l = [x**.5 for x in range(1, 11)]
print(f'''floats: [{", ".join(f"{x:.3f}" for x in l)}]''')
In [7]:
print(f"floats: [{\", \".join(f\"{x:.3f}\" for x in l)}]")
In [8]:
l = [x**.5 for x in range(1, 11)]
s = ", ".join(f"{x:.3f}" for x in l)
print(f'floats: [{s}]')
No comments:
Post a Comment