How to set column size using f-String in python?

Julina357 :

The Code:

for x in range(1, 11):
    for y in range(1, 11):
        print("{:5}".format(x * y), end = " ")
    print()

instead of using the .format() method I want to use f-string in this code but No idea how to set column in it.

norok2 :

It is pretty much the same, just leave the formatting part, i.e. everything from : onward, at the end:

for x in range(1, 11):
    for y in range(1, 11):
        print(f"{x * y:5}", end = " ")
    print()

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=407713&siteId=1