im new to python so this will be really easy for you guys i’m sure.
i wrote a simple thing in python, but i was curious how to put a period next to the variable i am using, i will show you here:
i = 5
print "i is equal to", i,"."
i run it and it comes out like this:
i is equal to 5 .
how do you make it so the (period) is right next to the 5, like “i is equal to 5.”
i tried searching for this but i feel like it too simple i can’t find it lol and i don’t know what things are called exactly, thanks.
Use string formatting:
As of Python 2.6, strings have a
.format()function that can alternatively be used:It’s useful if you have a placeholder that’s used multiple times in the format string: