Home arrow Python arrow Object Orientation in Python

Object Orientation in Python

Python is a very object-oriented language, which makes it easy to work with. For those of you who may not be familiar with the concept of object-oriented programming languages, Peyton provides a complete, easy-to-understand explanation, and then gives a number of examples that illustrate how object orientation works in Python.

TABLE OF CONTENTS:
  1. Object Orientation in Python
  2. Another Way to Understand Object Orientation
  3. Classes in Python
  4. More About Creating Classes
By: Peyton McCullough
Rating: starstarstarstarstar / 39
February 14, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

 

It seems that everywhere you go, you hear the term "object orientation" in relation to programming. However, it is a concept that many newcomers don't understand, especially if they are starting in languages that feature little or no object orientation.

In this article, we'll take a look at what object orientation is, the benefits it provides programmers and its impact on the programming community.

 

Object Orientation 101

 

Before we talk about what object orientation is, let's talk about what object orientation isn't. Object orientation isn't a simple string spat out sending a greeting to the world. Object orientation isn't a variable  modified by an external function, either. Think of a basic variable in, say, PHP. It's just a container and nothing more. It doesn't have a shape. It doesn't have mass. It doesn't have a color. It's just a void. (I have nothing against PHP, by the way, and I am aware that PHP is indeed object-oriented to an extent. This is merely an example.)

 

Now we'll dive into what object orientation is. Object orientation is all about, obviously, objects. These objects have their own data and their own methods that act on the data. For example, let's look this code:

 

aFile = open ( 'someFile.txt', 'w' )

 

The variable aFile is an object. Why? First of all, it has its own attributes which describe it:

 

aFile.closed

aFile.encoding

aFile.mode

aFile.name

aFile.newlines

aFile.softSpace

 

It also has its own methods. Methods are similar to functions, but they belong to objects and perform actions to the object's data:

 

aFile.close()

aFile.flush()

aFile.fileno()

aFile.isatty()

aFile.next()

aFile.read()

aFile.readline()

aFile.readlines()

aFile.xreadlines()

aFile.seek()

aFile.tell()

aFile.truncate()

aFile.write()

aFile.writelines()

 



 
 
>>> More Python Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: