Data Types
The operation of a Python program hinges on the data it handles. All data values in Python are objects, and each object, or value, has a type. An object’s type determines which operations the object supports, or, in other words, which operations you can perform on the data value. The type also determines the object’s attributes and items (if any) and whether the object can be altered. An object that can be altered is known as a mutable object, while one that cannot be altered is an immutable object. I cover object attributes and items in detail in Object attributes and items.
The built-in type(obj) accepts any object as its argument and returns the type object that is the type of obj. Built-in function isinstance(obj, type) returns True if object obj has type type (or any subclass thereof); otherwise, it returns False.
Python has built-in types for fundamental data types such as numbers, strings, tuples, lists, and dictionaries, as covered in the following sections. You can also create user-defined types, known as classes, as discussed in Classes and Instances.
Numbers
The built-in number objects in Python support integers (plain and long), floating-point numbers, and complex numbers. In Python 2.4, the standard library also offers decimal floating-point numbers, covered in The decimal Module. All numbers in Python are immutable objects, meaning that when you perform any operation on a number object, you always produce a new number object. Operations on numbers, also known ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access