Python for Dummies exaple

Chris Angelico rosuav at gmail.com
Wed Oct 14 07:58:01 EDT 2015


On Wed, Oct 14, 2015 at 8:55 PM, NewsLeecher User <newsleecher at spam.com> wrote:
> #class example
> class SayMyName:
>     def __init__(self, myname):
>         self.myname = myname
>     def say(self):
>         print "Hello, my name is", self.myname

Side point: This is a poor example for _any_ Python. In Py2, that
makes an old-style class, which will work fine until you try to use a
feature that it can't handle, and then you'll wonder what on earth is
wrong. And in Py3, the print calls need their parens. But it's a
pointless example of a class, which leaves you wondering why a better
example couldn't be found...

Definitely look for a better book, preferably one aimed at Python 3.4 or 3.5.

ChrisA



More information about the Python-list mailing list