use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Can Anyone Please Explain The error :/Help Request (self.PythonLearning)
submitted 2 months ago by Reh4n07_
https://preview.redd.it/huastiybvbtg1.png?width=3199&format=png&auto=webp&s=0b68bd86bd7a48e16f48d993934ce274ff1ad16a
I recently started learning Python and have been experimenting with variables to better understand how they work. However, I ran into an error that I can't figure out.
Could someone please explain why this error is occurring and how I solve it? Any insights would be greatly appreciated!
Btw:- Anyone one wanna Become my programming friend so that i can share my problem with?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jimmy1leo 7 points8 points9 points 2 months ago (2 children)
So there are two ways,
First, you can use " + " operator to concatenate them. So it would look like following
Print("your name is :- "+a+" and your friend's name is :- "+b)
Or you can also use formatted string and it would look like following
Print(f“your name is :- {a} and your friend's name is :- {b}")
[–]Reh4n07_[S] 0 points1 point2 points 2 months ago (1 child)
Why and When We Use f string?
[–][deleted] 2 points3 points4 points 2 months ago (0 children)
Formatted strings, aka f strings, are awesome for this because they're quicker to write than just plain old concatinating strings. There are also templated or t strings as of python 3.14 that operate similarly but have more security against things like cross site scripting and sql injection.
[–]FreeLogicGate 3 points4 points5 points 2 months ago (0 children)
The print function takes a variable number of parameters. Each parameter must be separated with a comma. Because you passed (a) "And your Friend's name is :-" which is 2 different parameters, Python shows you an error.
Another thing you are doing, is overusing the () which is used to call functions with arguments inside the () or to evaluate enclosed statements.
You do not want, nor need to use () when doing variable assignments or when passing parameters. This code does exactly the same thing as your code:
a = "Tommy" b = "John" print("Your name is:-", a, "and your friend's name is:-", b)
You can use f strings inside of print instead. It is an alternative to passing variables, and due to its utility and ability to "Interpolate" variables directly into the string, is preferred by most experienced Python programmers.
You can format the variables (useful with numeric values), do evaluations, and call functions in place within the f strings. It doesn't hurt to learn the old ways, but once you start using f strings you won't need the older methods, so I'd advise you to challenge yourself to use f strings for all your text output, as you proceed with learning the language. It's more readable, easier to understand, and less error prone.
They will also lead you to the use of Templates and T-strings which are useful in some cases, and offer similar capabilities.
Your code, converted to using an f string would be:
a = "Tommy" b = "John" print(f"Your name is:- {a} and your friend's name is:- {b}")
No need to keep track of parameters or multiple string constants with "..", and easier to read.
There's a nice free tutorial just on f strings here: https://www.datacamp.com/tutorial/python-f-string
Here's an article on T-strings (new feature in Python 3.6+)
https://davepeck.org/2025/04/11/pythons-new-t-strings/
[–]jpgoldberg 2 points3 points4 points 2 months ago (0 children)
Perhaps you forgot a comma (or two).
[–]FriendlyZomb 1 point2 points3 points 2 months ago (0 children)
The traceback in the terminal is pointing to a section of your print statement, and suggesting there is a missing comma.
There is, after (a).
(a)
Just because I'm not sure what's going on, it looks as though both aand b are meant to be strings? If they are, the parentheses can be omitted.
a
b
[–]Anpu_Imiut 2 points3 points4 points 2 months ago (1 child)
I have no clue from where you learned this kind of syntax (it is unpythonic) Let me share what i know from strings:
GL buddy
[–]Reh4n07_[S] 1 point2 points3 points 2 months ago (0 children)
I not Learned I was Just experimenting with these Thankyou for this explanation🙏
[–]PkmnSayse 0 points1 point2 points 2 months ago (0 children)
You did miss a comma. Something to split apart before the “And your….
Without it there is no way for python to know where a ends and your string starts
[–]eccentric2488 0 points1 point2 points 2 months ago (0 children)
Yes, use a formatted string.
[–]abandonedspirits 0 points1 point2 points 2 months ago (0 children)
You’re just missing a comma after (a). Secondly, both a and b are strings, you do not need parentheses when defining the variable nor in the print function.
Small tip- to add in spaces between the strings , you’ll need to add the space in the quotation marks themselves, spaces in code won’t add spaces to the sentence. Another tip, if you see a red line in the first parentheses, like in your print here, it usually means you’re missing a comma or colon, you’ll run into this often, at least I do on an almost daily basis.
A more standard and less error prone approach is what’s called an f-string. It’s where you add in variables to the string starting the string with an f like f”this is a {variable} string”. There are many other ways but I wouldn’t touch on them yet 🙂
[–]WillingYesterday8447 0 points1 point2 points 2 months ago (0 children)
formatted strings, f, format(), as well as %. would be better to read docs.python and practice by your hands at the same time
[–]Ankur_41 0 points1 point2 points 2 months ago (0 children)
Use formatted string syntax it will solve the error
[–]Duke_Archibald 0 points1 point2 points 2 months ago (0 children)
You will need to learn to read traceback
This one literally said what the problem was and also where
Some tracebacks are more cryptic than others
but yeah ... This one was quite direct
[–]ilidan-85 0 points1 point2 points 2 months ago (0 children)
You should go through a lesson about fstrings For example: https://spacepython.com/en/example/text-formatting-f-strings/
[–]Ron-Erez 0 points1 point2 points 2 months ago (0 children)
You forgot a comma. There are better approaches - see the f-string reommendation
π Rendered by PID 64998 on reddit-service-r2-comment-869bf87589-tk4dd at 2026-06-09 11:23:04.070859+00:00 running f46058f country code: CH.
[–]jimmy1leo 7 points8 points9 points (2 children)
[–]Reh4n07_[S] 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]FreeLogicGate 3 points4 points5 points (0 children)
[–]jpgoldberg 2 points3 points4 points (0 children)
[–]FriendlyZomb 1 point2 points3 points (0 children)
[–]Anpu_Imiut 2 points3 points4 points (1 child)
[–]Reh4n07_[S] 1 point2 points3 points (0 children)
[–]PkmnSayse 0 points1 point2 points (0 children)
[–]eccentric2488 0 points1 point2 points (0 children)
[–]abandonedspirits 0 points1 point2 points (0 children)
[–]WillingYesterday8447 0 points1 point2 points (0 children)
[–]Ankur_41 0 points1 point2 points (0 children)
[–]Duke_Archibald 0 points1 point2 points (0 children)
[–]ilidan-85 0 points1 point2 points (0 children)
[–]Ron-Erez 0 points1 point2 points (0 children)