Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104546

Re: Encapsulation in Python

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Newsgroups comp.lang.python
Subject Re: Encapsulation in Python
Date 2016-03-10 19:35 +0000
Message-ID <mailman.150.1457638586.15725.python-list@python.org> (permalink)
References <56E17985.7060002@benmezger.nl> <633796af251848feba7b6eed5e72e25a@seaexchmbx03.olympus.F5Net.com>

Show all headers | View raw


On 10/03/2016 14:57, Dan Strohl via Python-list wrote:
>> I've been studying Object Oriented Theory using Java. Theoretically, all
>> attributes should be private, meaning no one except the methods itself can
>> access the attribute;
>>
>> public class Foo {
>>      private int bar;
>>      ...
>

For the benefit of any newbies/lurkers I'll just point out that this 
might well be valid Java, but...

> Why?  I mean sure, lots of them should be, but if I am doing something like:
>
> class person:
>       age = 21
>       name = 'Cool Dude'
>

...this gives you class attributes, so the age is always 21 and the name 
is always 'Cool Dude'.  So you can vary the age and name you'd need:-

class person():
     def __init__(self, age, name):
         self.age = age
         self.name = name

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-10 19:35 +0000
  Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 15:52 -0800
  Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 17:12 -0800

csiph-web