0

Assigning without assign operator(=)?!

How can I do this?

8th Jan 2019, 1:27 PM
cocktus
cocktus - avatar
4 ответов
+ 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.
8th Jan 2019, 1:31 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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).
8th Jan 2019, 2:59 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
You can also use globals() instead of locals() to set global scope variable.
8th Jan 2019, 4:45 PM
Rugved Modak
Rugved Modak - avatar
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!
8th Jan 2019, 2:09 PM
cocktus
cocktus - avatar