Python
  Home arrow Python arrow Page 3 - Object Oriented Programming With Pytho...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Object Oriented Programming With Python (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2001-11-01

    Table of Contents:
  • Object Oriented Programming With Python (part 1)
  • A Very Big Snake
  • What's In A Name?
  • Digging Deep
  • Self-Involved
  • Under Construction

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Object Oriented Programming With Python (part 1) - What's In A Name?


    (Page 3 of 6 )

    Let's now add a few properties to the mix, by modifying the class definition to support some additional characteristics:

    class veryBigSnake: # some useful methods def eat(self): # code goes here def sleep(self): # code goes here def squeeze_to_death(self): # code goes here def set_snake_name(self, name): # code goes here self.name = name
    The class definition now contains one additional method, set_snake_name(), which modifies the value of the property "name". Let's see how this works:

    >>> alpha = veryBigSnake() >>> beta = veryBigSnake() >>> >>> # name the alpha snake >>> alpha.set_snake_name("Peter Python") >>> alpha.name 'Peter Python' >>> >>> # name the beta snake >>> beta.set_snake_name("Bobby Boa") >>> beta.name 'Bobby Boa' >>> >>> # rename the alpha snake >>> alpha.set_snake_name("Sally Snake") >>> alpha.name 'Sally Snake' >>>
    As the illustration above shows, once new objects are defined, their individual methods and properties can be accessed and modified independent of each other. This comes in very handy, as the next few pages will show.

    It's also important to note the manner in which object methods and properties are accessed - by prefixing the method or property name with the name of the specific object instance.

    More Python Articles
    More By icarus, (c) Melonfire


     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway