+ 3
What makes [a, b, c ... ] a list?
To create/get an object/instance of a user-defined class we do: <obj_name> = <class>([<some_object>]) And the same is true for built-in classes: E.g., a = int(), a = int(2.7) etc. But what makes a mere integer also an int object? In general, how do these become an instance of respective classes? 5 int 3.2 float [8, 1] list etc. And to my knowledge only built-in classes support this way to create objects.
5 Respuestas
+ 5
The system knows about its kernel built-in s.
The best fitting is chosen.
but it cant guess user classes.
if u want this behaviour, you could try to work with factory classes.
+ 1
In python we have type() function to get type of input we have given
+ 1
abhinav Yup, the interpreter knows that 12 is an object of the int class. This is a built-in behaviour. So 12 isn't actually an int but a reference to an int object containing the value '12' (I guess that class properties make this possible). You can check this out with the following code:
print(id(12))
a = 12
print(id(a))
0
Thanks Oma Falk
I believe it's related to the (conversions made by) interpreter.
But what are factory classes?
0
You're right Sâgærāvürï but what I'm asking is completely different