Formatted Strings

I copied 2 formatted string sequences from the lecture.

full = first + ’ ’ + last worked,

but full = f"{(first)} {(last)}" did not work

It appears that the ‘f’ function is not working. Is this right?


Hi @kushminer. Are you using double quotes or two single quotes on either side?

f"{(first)} {(last)}" should work but I suggest you remove the () from first and last. They are redundant in this instance.

Hi @paul,

I’m using double double quotes

Removed the ( )

Invalid syntax

Very odd. Can you try with single quotes?

Single quote with screen shot attatched.

This time I used terminal to print instead of Code Runner.

Using code runner, I received the error ‘invalid syntax’

Weird that I am getting different errors.

So this is indeed weird. When you run in the terminal, do you use the python or python3 command? You IDE suggests you are using python 3.10 which is fine. But you could get this error if your interpreter is python 2.


I had the same issue on Mac and I have sorted it with the following:

1: settings
2: in the search bar type: code-runner.executorMap
3: click Edit in settings.json
4: after the last code type a comma and press enter
5: on the next line type as follow “code-runner.executorMap”
6: lots of new codes will be displayed
7: amend the the python code (on mine it was on line 14) showing as
“python”: “python -u”, as follow:
“python”: “python3”,
8: save and exit

After this amendment, the formatting string started to work.

For help refer to “Lesson 9” of Getting Started. It is not the same on newer versions but the above should help.

I hope this helps