python – Getting an invalid syntax when trying to perform string interpolation

python – Getting an invalid syntax when trying to perform string interpolation

As suggested by Josh Lee in the comment section, that kind of string interpolation was added in Python 3.6 only, see What’s New In Python 3.6 (here its called PEP 498: Formatted string literals).

You, however, seems to be using Python 3.5.2, which does not support that syntax.

This is a pretty old question and not sure if answered somewhere else, but ran into same problem and landed on some confusing pages. Figured out a couple of minutes later. Below line should work.

my_message = I live in {}.format(state)

.format works for 3.5. Documenting it here for someone who may need it for similar issue.

python – Getting an invalid syntax when trying to perform string interpolation

What worked for me (in python 3.8.5 in sublime) was removing the f.

message = I live in {state}

I find it easier than .format(state)

Leave a Reply

Your email address will not be published.