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
5
  • What gives (after import sys) print sys.version? Commented Apr 23, 2020 at 10:03
  • Did you executed the program with python3 program.py? Commented Apr 23, 2020 at 10:28
  • @SergeBallesta 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)] Commented Apr 23, 2020 at 10:53
  • @SergeBallesta Why do they show different versions? f-strings were only implemented on versions 3.6 and later yes? Commented Apr 23, 2020 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. Commented Apr 23, 2020 at 13:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.