1 00:00:00,000 --> 00:00:09,573 [MUSIC] 2 00:00:09,573 --> 00:00:10,930 Hi Pythonistas. 3 00:00:10,930 --> 00:00:15,080 My name is Megan and I'm a teacher here at Treehouse. 4 00:00:15,080 --> 00:00:18,050 My pronouns are she, her, hers. 5 00:00:18,050 --> 00:00:19,110 In this course, 6 00:00:19,110 --> 00:00:23,277 I'll teach you about the wonderful world of object-oriented programming. 7 00:00:24,330 --> 00:00:25,935 I'm gonna start with a little advice. 8 00:00:25,935 --> 00:00:31,780 Object-oriented programming or OOP, can be confusing to learn, 9 00:00:31,780 --> 00:00:34,880 since it involves a different way of thinking about your code. 10 00:00:36,060 --> 00:00:40,200 It usually takes a bit before the knowledge sinks in and 11 00:00:40,200 --> 00:00:42,370 this new way of thinking clicks. 12 00:00:43,570 --> 00:00:47,600 My advice is to plan on rewatching videos, 13 00:00:47,600 --> 00:00:52,030 trying out some code on your own and asking lots of questions. 14 00:00:53,320 --> 00:00:54,040 Ready to jump in? 15 00:00:55,090 --> 00:00:55,837 Let's go. 16 00:00:55,837 --> 00:01:01,260 [SOUND] Object-oriented-programming is the way to structure 17 00:01:01,260 --> 00:01:05,769 your code into groups of properties and behaviors. 18 00:01:05,769 --> 00:01:07,700 These groups are objects. 19 00:01:08,730 --> 00:01:12,960 Structuring your code in this way is similar to a lot of real world objects. 20 00:01:14,050 --> 00:01:15,925 Let's use an example of a car. 21 00:01:15,925 --> 00:01:20,766 [SOUND] A car is an object that has properties like 22 00:01:20,766 --> 00:01:24,283 four wheels, at least two doors. 23 00:01:24,283 --> 00:01:28,380 It has a make, model and year it was made. 24 00:01:28,380 --> 00:01:35,160 It has behaviors like stop, go, and turning. 25 00:01:35,160 --> 00:01:39,027 All of these things make up our object car. 26 00:01:39,027 --> 00:01:45,680 Properties are things the object has, like a dog has a tail and two ears. 27 00:01:45,680 --> 00:01:51,070 While behaviors are usually things the object does, like bark or chase the ball. 28 00:01:52,652 --> 00:01:56,650 I wanna challenge you to think of an object on your own and 29 00:01:56,650 --> 00:01:59,920 list a few properties and behaviors. 30 00:01:59,920 --> 00:02:05,140 Pause this video, write or type your idea, and then unpause when you're ready. 31 00:02:06,260 --> 00:02:07,490 Go ahead and pause me. 32 00:02:09,570 --> 00:02:10,530 What did you come up with? 33 00:02:11,920 --> 00:02:13,910 The example I went with is a TV. 34 00:02:15,020 --> 00:02:21,050 Its properties are screen size, power buttons and HDMI ports. 35 00:02:21,050 --> 00:02:24,700 Its behaviors are turning off or on, increasing or 36 00:02:24,700 --> 00:02:27,290 decreasing the volume and muting the sound. 37 00:02:28,340 --> 00:02:33,130 You may be wondering why it is important to learn this way of structuring code. 38 00:02:33,130 --> 00:02:37,250 Well, OOP is a popular way to organize code and 39 00:02:37,250 --> 00:02:42,270 is how most of the libraries you have or will work with are structured. 40 00:02:43,320 --> 00:02:48,320 Knowing OOP will make understanding how those libraries work a lot easier. 41 00:02:50,020 --> 00:02:51,580 Think about strings. 42 00:02:51,580 --> 00:02:54,800 Strings are an object in Python. 43 00:02:54,800 --> 00:02:57,620 One property they have is they are immutable, 44 00:02:57,620 --> 00:02:59,500 which means they cannot be changed. 45 00:03:00,510 --> 00:03:04,960 Here I have a variable called my name that holds a string. 46 00:03:04,960 --> 00:03:07,180 If I try to change a letter to something else, 47 00:03:13,919 --> 00:03:14,980 I get an error. 48 00:03:16,310 --> 00:03:21,044 You have probably used a few of their behaviors already like lower, 49 00:03:21,044 --> 00:03:24,710 which turns the string into all lowercase letters. 50 00:03:24,710 --> 00:03:32,648 Upper which turns the string into all uppercase letters and format. 51 00:03:36,712 --> 00:03:40,719 Which lets you pass in some arguments to place inside of your string. 52 00:03:43,120 --> 00:03:49,490 Dictionaries, lists, sets and tuples are all Python objects too. 53 00:03:49,490 --> 00:03:53,510 Take a second to think about what their properties and behaviors are. 54 00:03:53,510 --> 00:03:56,238 Pause me and write or type your ideas. 55 00:03:56,238 --> 00:03:58,763 Go ahead. 56 00:03:58,763 --> 00:04:00,180 Back? 57 00:04:00,180 --> 00:04:02,980 In the teachers notes below, you can find a link 58 00:04:02,980 --> 00:04:07,140 to the Python documentation to find details on the string object. 59 00:04:08,430 --> 00:04:11,410 If you haven't looked at the Python documentation yet, 60 00:04:11,410 --> 00:04:14,450 I highly recommend you take some time to do so now. 61 00:04:15,770 --> 00:04:19,130 Knowing how to navigate documentation 62 00:04:19,130 --> 00:04:23,090 will become more important as you level up in your programming skills. 63 00:04:24,900 --> 00:04:29,540 To help solidify this new idea of object-oriented programming, 64 00:04:29,540 --> 00:04:32,620 try to think about things you've interacted with today, 65 00:04:32,620 --> 00:04:36,230 in terms of their properties and behaviors. 66 00:04:36,230 --> 00:04:37,530 Nice work Pythonistas.