Intro to OOP4:38 with Megan Amendola
Recall what oop is.
- OOP = Object-Oriented Programming
- Object-Oriented Programming = a way of structuring your code into groups of properties and behaviors
Example Object: Car
- 4 wheels
- 2 doors
Here are the Python docs about each of these objects. It's a good habit to check out the documentation and start getting used to reading about how things work.
Things I’ve interacted with today:
- Properties: 2 eyes, 2 ears, tail
- Behaviors: fetch, bark, whine, wag tail
- Properties: buttons, door, racks, light
- Behaviors: heating, timer, light on/off
[MUSIC] 0:00 Hi Pythonistas. 0:09 My name is Megan and I'm a teacher here at Treehouse. 0:10 My pronouns are she, her, hers. 0:15 In this course, 0:18 I'll teach you about the wonderful world of object-oriented programming. 0:19 I'm gonna start with a little advice. 0:24 Object-oriented programming or OOP, can be confusing to learn, 0:25 since it involves a different way of thinking about your code. 0:31 It usually takes a bit before the knowledge sinks in and 0:36 this new way of thinking clicks. 0:40 My advice is to plan on rewatching videos, 0:43 trying out some code on your own and asking lots of questions. 0:47 Ready to jump in? 0:53 Let's go. 0:55 [SOUND] Object-oriented-programming is the way to structure 0:55 your code into groups of properties and behaviors. 1:01 These groups are objects. 1:05 Structuring your code in this way is similar to a lot of real world objects. 1:08 Let's use an example of a car. 1:14 [SOUND] A car is an object that has properties like 1:15 four wheels, at least two doors. 1:20 It has a make, model and year it was made. 1:24 It has behaviors like stop, go, and turning. 1:28 All of these things make up our object car. 1:35 Properties are things the object has, like a dog has a tail and two ears. 1:39 While behaviors are usually things the object does, like bark or chase the ball. 1:45 I wanna challenge you to think of an object on your own and 1:52 list a few properties and behaviors. 1:56 Pause this video, write or type your idea, and then unpause when you're ready. 1:59 Go ahead and pause me. 2:06 What did you come up with? 2:09 The example I went with is a TV. 2:11 Its properties are screen size, power buttons and HDMI ports. 2:15 Its behaviors are turning off or on, increasing or 2:21 decreasing the volume and muting the sound. 2:24 You may be wondering why it is important to learn this way of structuring code. 2:28 Well, OOP is a popular way to organize code and 2:33 is how most of the libraries you have or will work with are structured. 2:37 Knowing OOP will make understanding how those libraries work a lot easier. 2:43 Think about strings. 2:50 Strings are an object in Python. 2:51 One property they have is they are immutable, 2:54 which means they cannot be changed. 2:57 Here I have a variable called my name that holds a string. 3:00 If I try to change a letter to something else, 3:04 I get an error. 3:13 You have probably used a few of their behaviors already like lower, 3:16 which turns the string into all lowercase letters. 3:21 Upper which turns the string into all uppercase letters and format. 3:24 Which lets you pass in some arguments to place inside of your string. 3:36 Dictionaries, lists, sets and tuples are all Python objects too. 3:43 Take a second to think about what their properties and behaviors are. 3:49 Pause me and write or type your ideas. 3:53 Go ahead. 3:56 Back? 3:58 In the teachers notes below, you can find a link 4:00 to the Python documentation to find details on the string object. 4:02 If you haven't looked at the Python documentation yet, 4:08 I highly recommend you take some time to do so now. 4:11 Knowing how to navigate documentation 4:15 will become more important as you level up in your programming skills. 4:19 To help solidify this new idea of object-oriented programming, 4:24 try to think about things you've interacted with today, 4:29 in terms of their properties and behaviors. 4:32 Nice work Pythonistas. 4:36
You need to sign up for Treehouse in order to download course files.Sign up