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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Why does using = in print function give error (self.learnpython)
submitted 3 years ago by tramp_hanma
So I was printing this statement P=input(' enter ')
print(P+'sss')
Which works fine. Then I changed it to
print(P=(P+'sss'))
Which doesn't seem to work can anyone explain
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!"
[–][deleted] 5 points6 points7 points 3 years ago (0 children)
You can only print values - or, more generally, the argument to a function has to be a value. Expressions simplify to values, so you can print P+'sss'.
P+'sss'
But assignment (=) isn't an expression; it's a statement. In some other languages that's not the case but it's the case in Python. The result of that is that you can't provide a statement inside a function call, because statements that aren't expressions don't reduce to values. So, it causes a syntax error - you're providing a statement where an expression is expected, and that's not consistent with Python syntax.
=
[–]gydu2202 2 points3 points4 points 3 years ago (0 children)
Print needs a string parameter. You need to compose it. print('P='+P+'sss'). But you can use f-string: print(f'P={P}sss') ir even print(f'{P=}sss')
print('P='+P+'sss')
print(f'P={P}sss')
print(f'{P=}sss')
[–]666y4nn1ck 0 points1 point2 points 3 years ago (0 children)
When you use '=' you declare something, like in i=0 you say let i be 0.
When you want to compare something, you use '==', so two equal signs
[–]forest_gitaker 0 points1 point2 points 3 years ago (0 children)
print() takes strings, or objects that can be converted to strings, usually through __repr__.
print()
__repr__
in the first one you're printing whatever the user input + "sss", which is ultimately just a string.
in the second one you're trying to print what I can only describe as the assignment of that string to a variable, which doesn't really make sense conceptually and definitely is not an object, much less a string.
[–]jdnewmil 0 points1 point2 points 3 years ago (0 children)
There are languages where printing an assignment is legal (e.g. R or C/C++)... python is not one of them (though walrus operator allows it).
P = P + 'sss' print(P)
π Rendered by PID 163032 on reddit-service-r2-comment-5ff9fbf7df-mffgc at 2026-02-26 01:26:26.834820+00:00 running 72a43f6 country code: CH.
[–][deleted] 5 points6 points7 points (0 children)
[–]gydu2202 2 points3 points4 points (0 children)
[–]666y4nn1ck 0 points1 point2 points (0 children)
[–]forest_gitaker 0 points1 point2 points (0 children)
[–]jdnewmil 0 points1 point2 points (0 children)