[Tutor] properties beginner M Dawson book
Steven D'Aprano
steve at pearwood.info
Sun Jun 10 14:11:39 CEST 2012
Nicholas Harman wrote:
> class Television(object):
> #Contstructor
Spelling error: Constructor.
Actually, technically __init__ is not the constructor. __init__ is the
initializer, as the object has already been created before __init__ is called.
__new__ is the constructor, although in this case it is unused.
> def __init__(self, name, channel = 1, volume = 5):
Optional: it is the usual convention to declare default values without a
space, that is, __init__(self, name, channel=1, volume=5).
> def main():
>
> tv_name = input("What do you want to call your television? ")
Are you using Python 2, or Python 3?
If Python 3, this is fine. But in Python 2, you should use raw_input instead
of input.
> tv = Television(tv_name)
>
>
> choice = None
> while choice != "0":
> print \
> ("""
> TV Maker
>
> 0 - Quit
> 1 - Television Details
> 2 - Set Channel
> 3 - Set Volume
> 4 - Chanage the name of the TV
> """)
Spelling: Change, not Chanage.
The rest seems fine to me, assuming you are writing for beginners.
--
Steven
More information about the Tutor
mailing list