Syntax error in Python when using f strings

When I put the following code into Sublime Text 3 (using Python 3.9.0), I receive a syntax error. Can someone tell me what I'm doing wrong? I'm following a YouTube tutorial very carefully, and when the instructor runs the same command, it works.

Note: the tutorial is using Python 3.7, but I thought using 3.9 shouldn't cause this issue?

greeting = 'Hello'
name = 'Michael'
message = f'{greeting} {name} !'
print(message)

1 answer

  • answered 2020-12-01 23:15 Krish Badri

    I don't get any error, but you can try

    message = '{} {}!'.format(greeting, name)
    

    as an alternative