Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82370 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-12-12 05:20 +1100 |
| Last post | 2014-12-12 05:20 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: is_<whatever_you_are_testing_for> as method or property? Chris Angelico <rosuav@gmail.com> - 2014-12-12 05:20 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-12-12 05:20 +1100 |
| Subject | Re: is_<whatever_you_are_testing_for> as method or property? |
| Message-ID | <mailman.16862.1418322408.18130.python-list@python.org> |
On Fri, Dec 12, 2014 at 4:34 AM, Mateusz Loskot <mateusz@loskot.net> wrote: > If a class member function simply tests something and > returns a b::oolean call it > > def is_<whatever_you_are_testing_for>(): > pass > > like 'is_even'. > > Should I define it as a classic method > > def is_even(self): > pass > > or as a property > > @property > def is_even(self): > pass A property should be used if what you're creating is "virtually an attribute". If it would make sense to have an attribute is_even, then a property is_even makes sense. If in doubt, go with a method. ChrisA
Back to top | Article view | comp.lang.python
csiph-web