Python Forum

Full Version: f-string issues in 3.6.9 (?)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all,

I'm pretty new to the world of Python but I would really appreciate some help with a small problem I seem to be having. If it helps, I am using Ubuntu Linux 18.04 on Virtual Box from a Windows 10 laptop with gnome desktop. Entering the command 'Python3' in the terminal shows me that I have Python 3.6.9 installed. I am using sublime text editor to work on some basic coding.

Right now I am having a problem with f-strings. I am using the book "PYTHON crash course" and am currently on page 21. From what I have read online F-String were updated in Python 3.6 so you include 'f' before the parenthesis, which would do that same thing as '.format' in earlier versions of Python. My problem is that whenever I attempt to run a code with 'f' I get a syntax error. I'm not sure if my version is incorrect, I am entering the code incorrectly, or something else entirely is wrong. Below is a description of the issue I am having. I re-wrote the code because I cannot copy and paste from the virtual box... not exactly sure how to fix that either Confused

first_name = "ada"
last_name = "Lovelace"
full_name = f"{first_name} {last_name}"
print{full_name}
After running this code I receive an error message stating something akin to

"SyntaxError: invlalid syntax" and it shows me the full path of my shell_cmd, dir and path. Any ideas on why this is giving me an error? I appreciate your help!
print uses parenthesis, not brackets
print(full_name)
(Feb-08-2020, 02:49 AM)Larz60+ Wrote: [ -> ]print uses parenthesis, not brackets
print(full_name)

Sadly that did not fix the issue, but I do appreciate the guidance. I am still receiving the original syntax error.
(Feb-08-2020, 02:33 PM)KSterner Wrote: [ -> ]Sadly that did not fix the issue

It did

first_name = "ada"
last_name = "Lovelace"
full_name = f"{first_name} {last_name}"
print(full_name)
Output:
ada Lovelace
If it did not fix the error you need to post the whole traceback