Michael Lewis wrote:
Why don't I have to import str or list to access their attributes like I do
with the math or random or any other library?


Because they are built-in. That means they live inside the Python compiler/interpreter itself.

They are built-in because str, list, etc. are fundamental data types, used by the core Python interpreter, so they need to be available from the moment Python starts up, even before your code starts to run.

Other built-in objects include:

None
True and False
Ellipsis
NotImplemented
int
float
tuple
dict
many different exceptions such as ValueError, TypeError, etc.
many different functions, such as len, chr, abs, enumerate, etc.


Some of these are built-in because the interpreter won't run without them.

Some are built-in for convenience and speed: although the interpreter will run without them, they are so useful that it makes sense to treat them as critical, core objects.

And some are built-in just because they were built-in many years ago, and for backwards compatibility they have to stay built-in. (I'm thinking of functions like compile and eval.)



--
Steven

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to