Python Forum
f-string issues in 3.6.9 (?)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
f-string issues in 3.6.9 (?)
#1
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!
Reply
#2
print uses parenthesis, not brackets
print(full_name)
Reply
#3
(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.
Reply
#4
(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
Reply
#5
If it did not fix the error you need to post the whole traceback
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  String formatting (strptime) issues Henrio 2 838 Jan-06-2023, 06:57 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020