I am a beginner in Python and I was learning string formatting when I encountered this problem. The code is
Age = 22
Month = "November"
Year= 1991
Gf= "julie"
print("The age of Smith is {Age} and he was born in {Month}{Year} and his girlfriend name is
{Gf}".format(Age,Month,Year,Gf))
When I run it, the error is KeyError:'Age'. Why is it happening?
It works fine when I use an f-string.
Age = 22
Month = "November"
Year= 1991
Gf= "julie"
print(f"The age of Smith is {Age} and he was born in {Month}{Year} and his girlfriend name is
{Gf}")
.format(Age=Age, Month=Month, ...).