Search code examples
pythonpython-3.xsyntax-error

fstring gives SyntaxError: invalid syntax


I'm trying to learn python using Python Crash Course 2ND EDITION so it's not the latest edition but it's using Python 3.6 i guess. my python version is 3.10.11

this is my code:

names = ['sepehr', 'farzad', 'mahan', 'arting', 'saeed']
message = f"greeting my dear friend ! {names [0].title()}".
print (message)

when i try to run the code in cmd i get this:

  File "M:\My codes\Python_Crash_course\Chapter-3\greetings.py", line 2
    message = f"greeting my dear friend ! {names [0].title()}".

any help would be appreciated, thanks !

(i tried rewriteng the code but i got the same result)


Solution

  • remove "." at the end of message = line and it should work

    message = f"greeting my dear friend ! {names [0].title()}"