Lecture13-ClassImplementation-Part1-3pp

Def getfavefoodself return selffavefood 8 methods

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: nstance of the list class, and 
 # contains instances of the string class
 my_list = [“a”, “b”, “c”]! ! # type() lets you discover the type or class of 
 # an object
 >>> type(5)
 <class 'int'>! 7 A class! class Person: ! fave_food = "pizza"! ! def __init__(self, name, city):! self.name = name! self.city = city! ! def get_name(self):! return self.name! ! def get_city(self):! return self.city! ! def move(self, new_city):! self.city = new_city! ! def get_fave_food(self):! return self.fave_food! 8 Methods and Members • Define a class using the class keyword • FuncDons can be defined inside a class   These funcDons are called methods • Variables can be added inside a class   These variables are called members or member variables 9 3 13 ­11 ­13 Constructors • The constructor is a special method inside a class • It tells Python some informaDon about how to create a new instance of the class • The...
View Full Document

This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online