0
Assigning without assign operator(=)?!
How can I do this?
4 Respostas
+ 3
Hey cocktus
You are messing with operators.
(+) Is not assignment operator(of course it's plus sign)
You have to use equal to(=) sign for assignment.
I don't think it is possible to do assignment without assignment operator.
+ 2
Instead of x=2, you could do something like
locals().__setitem__('x', 2)
print(x) # Output: 2
But I have no idea why anyone would want to do that (other than some of us who like to write one-lined versions of long codes for fun).
+ 1
You can also use globals() instead of locals() to set global scope variable.
0
yes, sorry for that. I already replaced that + by =.
I neither found anything about that method. It would be nonsense too I think.
anyway, thanks for comment!