Is -1 a int in python?



I am quite confused why when I:
print type(-1) --------->"int"
print -1 == int --------------> False

So this seems to me when I use type function to check what -1 type is, python tell me it is int.
But when I tested if -1 is int python tell me it is not int.

I am quite confused.
Thank you


-1 is of type integer, that doesn’t mean it equals the data type. A value doesn’t equals its belonging data type.


If both of these were True

-1 == int
-2 == int

… then this would also be True

-1 == -2

Clearly, that is not the case.

An object is not the same thing as its type, just as an individual animal is not the same thing as its species.

Therefore, we should not generally assume this is True

x == type(x)

However, there is a value of x for which the above is True. Can anyone guess what it is?


Methinks @ionatan got it :wink:
17 AM


And then I spent a good 20 minutes lying down trying to figure out whether it’s the egg or the chicken that comes first…Not that the analogy entirely fits, /me googles plato

Plato was going a step further and asking what Form itself is.


From Wikipedia: Chicken or the egg

If the question refers to chicken eggs specifically, the answer is still the egg …

… but me asks, what if chickenhood, as we want to define it, arose from a particular mutation, and we don’t know whether that occurred in an egg or an adult bird?

With respect to programming languages, the original FORTRAN did distinguish various types, but the abstraction had not yet been carried forth to implement the notion of type, itself, as an instance of itself.


Bend the rules of the problem just a little bit (mutation/Python is made out of C) and one can keep going a bit further, only to eventually encounter another unexplainable “there was stuff”


str = type(str)?

No idea, this is beyond me. :stuck_out_tongue:

but can i have the answer haha.


Types are objects in Python, so they too must have a type. The type of types is therefore also its own type.
The chicken and egg problem with that is that to create a type, a type for types is needed. I’m pretty sure the trick to doing that is to define it using magic, something out of this world, and that’s something we have because Python is written in another language, C. It’s a bit like the big bang, suddenly there’s Existence (things get added with C, which from Python’s perspective, is out of nowhere). This keeps going for a while like a Russian nesting doll, after a few iterations you leave computers and enter “our reality” and reach the same unexplainable limit of "how did it all begin"
There might be some flaws/limits/mistakes in that thought, but for what it is, I think it’s neat.
And, if you imagine a system that is made from building blocks on the “outside” that can’t be seen on the “inside” (just exists out of nowhere, magic, unexplainable), then it may be difficult to figure out what is going on when observing from within that system even though it might be easy to explain from an outside perspective – until you try to explain how that layer came to be (what/which is the base existence?). This might be either super obvious or not at all accurate to our universe-situation, I can’t tell.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.