Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

Class Instances

Instances of a class are created by calling a class object as a function. This first creates a new instance by calling the static method __new__(), which is rarely defined by the user, but implemented as part of object. This, in turn, calls the __init__() method of the class, which is almost always defined by a user to initialize the contents of an instance. For example:

# Create a few accounts
a = Account("Guido", 1000.00)  # Invokes Account.__init__(a,"Guido",1000.00)
b = Account("Bill", 10.00)

The attributes and methods of the newly created instances are accessible using the dot (.) operator as follows:

a.deposit(100.00) # Calls Account.deposit(a,100.00) b.withdraw(50.00) # Calls Account.withdraw(b,50.00) name = a.name # Get ...
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.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book