Seeing information about a Python object

In interactive mode, there are two ways to see information about an object:

• Type the object (or its name) and press Return.

• Type the print command and the object (or its name) and press Return. What you see depends on what the object is.

• With some data types (integers and lists, for example), the two methods of seeing the value give the same result—as in this example, in which the name stores a list:

• With strings, the result of typing print name and pressing Return is slightly different from the result you get by typing name and pressing Return. When you just type name and press Return, the value is surrounded by quotation marks, but when you type print name and press Return, there are no quotation marks. (To find out why, see the sidebar, "Representing data".)

This example shows the difference between using just the name and using the print statement with the name:


• When the name refers to a code block (for example, a function, module, or class instance), looking at the name shows you information such as the kind of data, the name, and the storage location.

This example creates a class called Message and displays information about the class:

<class main .Message at 0x58db0> >>> print Message main .Message

Was this article helpful?

0 0

Post a comment