Search code examples
pythonbuilt-in

What is the relationship between Python built-in modules and built-in types/functions?


Built-in types and functions could be used without importing, like 'list, dict, print' .

But built-in moudles still need importing before using, like 'time, sys, gc, math, mmap'.

So they are just different conceptions, or built-in moudles include built-in types/functions?


Solution

  • There's no relationship whatsoever between the built-ins namespace and built-in modules. Stuff that's accessible without importing is that way because it's been inserted into a special built-ins namespace, available through the builtins module, while built-in modules are a special subset of standard library modules that are compiled directly into the Python interpreter executable. They're completely unconnected usages of the word "built-in".

    The "built-in" in <built-in function whatever> is another completely unrelated meaning - when you talk about built-in types and functions being usable without importing, that's really a property of the built-ins namespace, while a function showing up as <built-in function whatever> just means it's written in C.