Reputation: 117
I would like to add space after I write text and my variable in Python Format String. So I want to align and add 50 spaces such as the below picture.
I wrote this code but it does not work
print("{:<50s}{}".format("Enter the point ID of unknown point ",i,)," :",end=" ")
Upvotes: 0
Views: 625
Reputation: 42768
You have to first format your prompt, and in a second step print this prompt:
prompt = f"Enter the point ID of unknown point {i}"
print(f"{prompt:<50s} : ", end="")
or count, how many places are left for the number:
print(f"Enter the point ID of unknown point {i:<14d} : ", end="")
Upvotes: 1
Reputation: 3011
Use f-string literal to solve this
Spaces = ' ' * 50
print(f"Enter the point ID of unknown point : {i}{Spaces}")
Use {Spaces}
wherever you want to add 50 spaces
Upvotes: 0