ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] OOPs Concept
by Matthew White other posts by this author
Apr 19 2006 8:33AM messages near this date
[Tutor] OOPs Concept | Re: [Tutor] OOPs Concept
Even though I am still new to python, I've recently had an insight as
to what makes OOP different from procedural programming.

Let's take perl for example.  A variable in perl is like a bowl.  It's an
empty vessel you can put things in.  You can change the contents of
the bowl, you can empty the bowl but it doesn't really *do* anything.
It has no real attributes aside from the fact that it's a container.

So when I create a variable in perl it looks like this:

$x = 'hello'

If I want to make the first letter of the value of $x a capital letter,
I have to use a function to do it:

$y = ucfirst($x)

now $y contains the value 'Hello'

In python one doesn't really create variables, one creates objects.
Sring objects, list objects, etc.  And objects are cool because they can
do things.  They are more than just merely bowls, they are like swiss
army knives.  So in python, if I say:

x = 'hello'

Then I can do all sorts of things with x:

x.capitalize()  ->  'Hello'
x.swapcase() ->  'HELLO'
x.count('l') ->  2

This is just a very small example but I hope that my example can help
you understand what objects are what makes OOP different from procedural
programming.

-mtw

On Wed, Apr 19, 2006 at 06:07:27PM +0530, Kaushal Shriyan (kaushalshriyan@gmail.com) wrote:
>  Hi All
>  
>  I wanted to understand about OOPs Concept in Python in a easy way,
>  Please explain me with an example
>  
>  I have been reading http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm
>  but at the moment still the concept is not clear
>  
>  Thanks in Advance
>  
>  Regards
>  
>  Kaushal
>  _______________________________________________
>  Tutor maillist  -  Tutor@[...].org
>  http://mail.python.org/mailman/listinfo/tutor

-- 
Matthew White - District Systems Administrator
Tigard/Tualatin School District
503.431.4128

"The greatest thing in this world is not so much where we are, but in
what direction we are moving."   -Oliver Wendell Holmes

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Kaushal Shriyan
Matthew White
Kaushal Shriyan
Matthew White

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved