[Tutor] OOPs Concept

Kaushal Shriyan kaushalshriyan at gmail.com
Wed Apr 19 17:40:41 CEST 2006


On 4/19/06, Matthew White <mwhite3 at ttsd.k12.or.us> wrote:
> 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 at 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 at python.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
>
>

Thanks Matthew
Just wanted to know
x.count('l') -> 2 Here 2 means what I didnot understood this
and also does x is a object and capitalize(), swapcase()  and
count('l') are methods, is that correct what i understand

Awaiting your earnest reply

Regards

Kaushal


More information about the Tutor mailing list