Python
  Home arrow Python arrow Page 3 - Object Oriented Programming With Python (part 1)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

Object Oriented Programming With Python (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 28
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek