Can someone explain to me what is going on with the .format() method that it only works off a string declaration and not on a variable containing a string?
Below are the example of the working and failing code followed by the output of each
# This works fine
s = "{0} \n" \
"{1} \n" \
"{2}\n" \
.format("Hello", "world", "from a multiline string")
print(s)
# This does not
f = "{0} \n" \
"{1} \n" \
"{2}\n"
f.format("Hello", "world", "from a multiline string")
print(f)
respective output
Hello
world
from a multiline string
{0}
{1}
{2}
I have tried this with no numbers in braces({}
) as well as by assigning names ({aname}
) and passing keyword arguments. I'd like to understand the difference between the first and second examples in how the format method processes them, and if there is a way to format a variable containing a string separate from the actual declaration.