Fixed digits after decimal with f-strings
Include the type specifier in your format expression: >>> a = 10.1234 >>> f'{a:.2f}’ ‘10.12’
Include the type specifier in your format expression: >>> a = 10.1234 >>> f'{a:.2f}’ ‘10.12’
To answer your first question… .format just seems more sophisticated in many ways. An annoying thing about % is also how it can either take a variable or a tuple. You’d think the following would always work: “Hello %s” % name yet, if name happens to be (1, 2, 3), it will throw a TypeError. … Read more