Skip to content

Instantly share code, notes, and snippets.

@zhangkaizhao
Last active April 10, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangkaizhao/6be058d9e3e1ccc69b068316943f4622 to your computer and use it in GitHub Desktop.
Save zhangkaizhao/6be058d9e3e1ccc69b068316943f4622 to your computer and use it in GitHub Desktop.
Python `__eq__` compared to JavaScript closure
// via Telegram Desktop CPyUG group fy
// https://stackoverflow.com/a/48298565/2837824
const a = {
i: 1,
toString: function() {
return a.i++;
}
}
if (a == 1 && a == 2 && a == 3) {
console.log("Hello World!");
}
class Number:
def __init__(self, value=1):
self.value = value
def __str__(self):
return str(self.value)
def __eq__(self, another_value):
# print(self.value)
result = self.value == another_value
self.value = self.value + 1
return result
a = Number()
if a == 1 and a == 2 and a == 3:
print("Hello World!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment