FYI: What you're describing is not a Nash equilibrium, but a Pareto optimal point [1]. They are similar in that you couldn't do any better, but Nash equilibria is in terms of whether this would cause other players to change their strategies, while Pareto optimality is only about trading off different features/dimensions.
It is, at a first glance, a bit weird. But the way you should look at it is that Python the language doesn't say the two integers have the same identity, and you shouldn't assume they will. But it also doesn't say they can't be the same object. Since Python integers are immutable, and thus having the two variables actually reference the same object can't create side effects unless you're directly playing with identities and making assumptions in your code that you shouldn't make, the implementation can have the two variables reference the same object as an optimization without breaking anything.
I used to test for None by doing what seemed to work:
if my_variable:
do something
until I discovered it doesn't work if my_variable = 0 or some other falsy value besides None. missing = object()
def func(a=missing):
if a is missing:
raise ValueError('you must pass a')
This "numbers less than 256 are the same objects" is a fairly common on the list of "wtf python" but I've never understood it. You don't use `is` like that and you would never use it in code because the operator you're using is not the right one for the thing you're trying to do.Plus if this is the biggest wtf then that's pretty good going.
BTW, that's not the "biggest" WTF feature; it's just my favorite. There's a long list of WTF features here:
https://github.com/satwikkansal/wtfpython
Otherwise, I agree, it's a pretty good going :-)
This belief seems common, but I always wonder if anyone with familiarity with dynamic programming languages that were implemented by people who knew what they are doing (as implementers) thinks so. Self, Smalltalk and Common Lisp, for example, are doing much better on the ad-hoc interactivity front in non-trivial ways whilst offering implementations with vastly better performance preceding (C)Python by many years. The fact that python has terrible execution speed is most due to lack of relevant skills in the community not some conscious engineering trade-off.
Having said that, I don't think you are wrong on python being "the least worst language for everything" -- very few other languages have an eco system of remotely comparable expansiveness and quality (the top minds in several disciplines mostly use python for their work) which alone kills of huge swathes of would-be-competitors.
Yes, I agree. The ecosystem is part of what makes the language "the least worst language for everything."
In [2]: (1, 2) is (1, 2)
Out[2]: True
In [3]: a, b = (1, 2), (1, 2)
In [4]: a is b
Out[4]: True
In [7]: a = (1, 2)
In [8]: b = (1, 2)
In [9]: a is b
Out[9]: FalseQuick Google gives: https://stackoverflow.com/a/1515811
I think you can say that about almost any language. Each feature has it's advantages and disadvantages and even the most hated features of some languages have some reasoning behind them - so changing it would hurt some use case.
Language design is sometimes more about reasonable compromises than genius ideas.
>>> a=257
>>> b=a
>>> a is b
True
What you want is double equals.
It's never the absolute best language for anything, but it's hard to improve it on any front (e.g., execution speed) without hindering it on other fronts (e.g., ad-hoc interactivity), and it's never the absolute worst language for anything. Often enough, it's good enough.
Python might well be "the least-worst language for everything."
--
[a] https://en.wikipedia.org/wiki/Nash_equilibrium