Ugohihi
Ugohihi

Reputation: 25

Python3 f-strings only interpreted in bash

I am currently learning python and have noticed an issue: If I write a .py file and interpret it with the python3 myfile.py command line then the f-string below simply won't show, but if I do the same directly in the python bash it works just fine.

Where could this come from ? (my python version is 3.6.4 (I also have a 2.7 version installed) and I work on macOS)

a = "Hello"
b = 22
f"{a} I'm {b} years old"

Upvotes: 1

Views: 2083

Answers (1)

wim
wim

Reputation: 363566

That's normal, when executing code in the interactive Python interpreter there is a REPL - read, evaluate, print loop.

When executing from a .py file, there is no REPL. If you want the string to appear on stdout, you will need to actually print it:

print(f"{a} I'm {b} years old")

Upvotes: 4

Related Questions