Why Use Built-in Types?
Here are some reasons why:
• Built-in objects make programs easy to write. For simple tasks, built-in typesare often all you need to represent the structure of problem domains. Because you
get powerful tools such as collections (lists) and search tables (dictionaries) for free,
you can use them immediately. You can get a lot of work done with Python’s builtin object types alone.
may need to provide your own objects using Python classes or C language interfaces. But as you’ll see in later parts of this book, objects implemented manually
are often built on top of built-in types such as lists and dictionaries. For instance,
a stack data structure may be implemented as a class that manages or customizes
a built-in list.
Python’s built-in types employ already optimized data structure algorithms that
are implemented in C for speed. Although you can write similar object types on
your own, you’ll usually be hard-pressed to get the level of performance built-in
object types provide.
borrows both from languages that rely on built-in tools (e.g., LISP) and languages
that rely on the programmer to provide tool implementations or frameworks of
their own (e.g., C++). Although you can implement unique object types in Python,
you don’t need to do so just to get started. Moreover, because Python’s built-ins
are standard, they’re always the same; proprietary frameworks, on the other hand,
tend to differ from site to site.
also more powerful and efficient than most of what can be created from scratch. Regardless of whether you implement new object types, built-in objects form the core of every Python program.
摘至:<<Learning Python>> 5th Edition