W10_Classes-4up - CSCA08H/108H Week 10 2.5 more weeks of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCA08H/108H Week 10 2.5 more weeks of classes! Yikes!! Classes (Object-Oriented Programming) Using objects You have used many kinds of objects that are built in to Python: int, str, list, dict, etc. total = 0 # Create a new int object. name = “Priya” # Create a new str object. And others that are part of modules you had to import, such as media. import media p = media.get_pixel(pic, 3, 92) # Returns a Pixel object. Classes Every type of data in Python ( lists, labels, integers, strings, StringVars, dictionaries, windows … ) is a class Every value in Python is an instance of its class (class instances are also called objects ) of that class Classes deFne behaviour for their instances: the fact that any list has a sort method to sort that list's contents the fact that any string has a split method 4 1 2 3 4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Defning new types oF objects Consider a calendar program. One oF the basic things you’d need to keep track oF is events. What should we keep track oF For a single event? We could defne individual variables For each oF these, but we’d need to do that For every event. Messy. Or we could defne a new type oF object to bundle these
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

W10_Classes-4up - CSCA08H/108H Week 10 2.5 more weeks of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online