- 1

Can variables be manipulated within a print statement? (Python) Like: x = 3 print(x *=3)

Variables and 'print'

1st May 2020, 11:08 AM
Megha Suresh
4 Answers
+ 1
Pls add Language name in tag where you have added operator,also your question isn't clear if you could provide more details or code on what you mean that will be helpful
1st May 2020, 11:15 AM
Abhay
Abhay - avatar
+ 1
Assignation statements have no return value in Python (conversely to others languages such as JS)... So theoricaly, you could expect "None" outputed by printing such things... but it fail with errors, either explicit (raised) or implicit (logical): >>> print(a=42) TypeError: 'a' is an invalid keyword argument for this function >>> print(end=42) TypeError: end must be None or a string, not int >>> print(end="forty-two") forty-two>>> print(end) NameError: name 'end' is not defined >>> end = 42 >>> print(end="forty-two") forty-two>>> print(end) 42 >>> x = 3 >>> print(x*=3) SyntaxError: invalid syntax
1st May 2020, 5:21 PM
visph
visph - avatar
0
No but they can be mapped
1st May 2020, 11:30 AM
Oma Falk
Oma Falk - avatar