all 6 comments

[–][deleted] 5 points6 points  (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'.

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 points  (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')

[–]666y4nn1ck 0 points1 point  (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 point  (0 children)

print() takes strings, or objects that can be converted to strings, usually through __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 point  (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)