Lecture13-ClassImplementation-Part1-3pp

Lecture13-ClassImplementation-Part1-3pp

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: constructor is always called __init__   FuncDons with double underscores have special meaning to Python (there are a lot of them, but this is the only one we’ll use for now) • The constructor has at least one parameter… self 10 “self” • Methods in a class need to know which object they are referring to • The first parameter in any method refers to the parDcular instance of the class the method was called on • The convenDon is to use self as this parameter • You can refer to methods and members of self 11 The Person class • Methods in the Person class:   __init__(self, name, age) # the constructor!   get_name(self)   get_city(self)   move(self, city)   get_fave_food(self) • Member variables in the Person class:   fave_food   name # created in the constructor   city # created in the constructor 12 4 13 ­11 ­13 Using a class • Aeer defining the Person class, we can use it ! # creates a new instance of the Person class
 # by calling the construc...
View Full Document

This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online