Linux/Unix > Python Essential Reference, Second Edition > 3. Types and Objects > Terminology | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238110137104028131048028205197128

### Terminology

Every piece of data stored in a program is an object. Each object has an identity, a type, and a value.

For example, when you write `a = 42`, an integer object is created with the value of `42`. You can view the identity of an object as a pointer to its location in memory. In this example, `a` is a name that refers to this specific location.

The type of an object (which is itself a special kind of object) describes the internal representation of the object as well as the methods and operations that it supports. When an object of a particular type is created, that object is sometimes called an instance of that type (although an instance of a type should not be confused with an instance of a user-defined class). After an object is created, its identity and type cannot be changed. If an object’s value can be modified, the object is said to be mutable. If the value cannot be modified, the object is said to be immutable. An object that contains references to other objects is said to be a container or collection.

In addition to holding a value, many objects define a number of data attributes and methods. An attribute is a property or value associated with an object. A method is a function that performs some sort of operation on an object when the method is invoked. Attributes and methods are accessed using the dot (`.`) operator, as shown in the following example:

    a = 3 + 4j          # Create a complex number
    r = a.real          # Get the real part (an attribute)

    b = [1, 2, 3]       # Create a list
    b.append(7)         # Add a new element using the append method

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.