0

I'm getting a syntax error on my f-string statements even though i'm using python version 3.7.4

 my_name= "raushan"
 print(f"Let's talk about {my_name}")

File "<ipython-input-5-0b1a3af6fa22>", line 2
    print(f"Let's talk about {my_name}")
                                      ^
SyntaxError: invalid syntax

python version i'm using.

!python --version

Python 3.7.4
Ganesh
  • 19
  • 5
  • What gives (after `import sys`) `print sys.version`? – Serge Ballesta Apr 23 '20 at 10:03
  • Did you executed the program with `python3 program.py`? – Louis Lac Apr 23 '20 at 10:28
  • @SergeBallesta 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)] – Ganesh Apr 23 '20 at 10:53
  • @SergeBallesta Why do they show different versions? f-strings were only implemented on versions 3.6 and later yes? – Ganesh Apr 23 '20 at 10:55
  • It looks like you are using ipython. It uses its own version of Python (here 3.5.6) while your path uses a 3.7.4 version. Having multiple versions of Python is normally not a problem provided you are aware of it and know which tool uses which version. – Serge Ballesta Apr 23 '20 at 13:06

1 Answers1

1

I don't have enough reputation to comment so I'll do it here. I believe that your error is that in line 2 before the print statement, you added an unnecessary space (indent). Python doesn't like unnecessary indents.

Does this work for you?

my_name= "raushan"
print(f"Let's talk about {my_name}")

Edit: Apparently both the lines have unnecessary indents.