Is -1 a int in python?

#1

Hi,

I am quite confused why when I:
print type(-1) --------->"int"
but
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

#2

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

#3

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?

#4

Methinks @ionatan got it â€¦

#5

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.

#6

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.

#7

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â€ť

#8

str = type(str)?

No idea, this is beyond me.

but can i have the answer haha.

#9

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.

#11

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