O'Reilly logo

The Quick Python Book by Naomi R. Ceder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 19. Data types as objects

This chapter covers

  • Treating types as objects
  • Using types
  • Creating user-defined classes
  • Understanding duck typing

By now, you’ve learned the basic Python types and also how to create your own data types using classes. For many languages, that would be pretty much it, as far as data types are concerned. But Python is dynamically typed, meaning that types of things are determined at runtime, not at compile time. This is one of the reasons Python is so easy to use. It also makes it possible, and sometimes necessary, to compute with the types of objects (and not just the objects themselves).

19.1. Types are objects, too

Fire up a Python session, and try out the following:

>>> type(5)<class 'int'>>>> type(['hello', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required