I am new to Python. I am familiar with Java, C/C++, and OCaml. I understand Lambda Calculus and elementary Type Theory because of a Programming Languages course I took at University.
Armed with this background, I tried to read this - http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html
Somewhere down, he mentions this:
I am not able to wrap my poor brain around this:
What the bleep is happening here? What I want to hear is extremely in depth reasons on what exactly is happening here, and why things are the way they are. No shallow reasons or analogies please.
Python types are ordinary objects just like anything else (everything is an object). Being a type or an instance is a matter of the object's semantics, a role that it plays. Class, or type, is an object that holds information about how to construct a certain kind of objects and what that kind of objects can do.
A 'data-type' is a type of data such as an integer, a boolean, or a character. It defines what values a variable of a 'data-type' can hold and what operations can be performed on it. An object is an instance of a class.
Python is a dynamically typed langage as opposed to statically typed. This means that the Python interpreter does not necessarilly know the type of the objects before the actual code execution.
Python has a lot of built-in functions. The type() function is used to get the type of an object. When a single argument is passed to the type() function, it returns the type of the object. Its value is the same as the object.
It is talking specifically about the object type
. For type
, all types inherit from <type 'type'>
.
I believe the other statement is just pointing out that <type 'type'>
is an object
; an example I thought of from looking further down:
t = list.__class__ # <type 'type'>
t.__bases__ # (<type 'object'>,)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With