1 00:00:00,480 --> 00:00:04,630 Hello everybody and welcome back to Python basics tutorials. 2 00:00:04,770 --> 00:00:08,010 Now we covered functions in the previous video. 3 00:00:08,010 --> 00:00:12,540 We also cover some of the loops while loops if loops for statements and all of that. 4 00:00:12,540 --> 00:00:18,720 We covered some of the Python basic such as variables and we also covered some of the most basic programs 5 00:00:18,750 --> 00:00:21,090 that you can write with python. 6 00:00:21,450 --> 00:00:26,660 But right now what we want to do is actually show you another thing that is in Python. 7 00:00:26,820 --> 00:00:34,520 Since python is project these object oriented languages many of the code in for example big parts of 8 00:00:34,520 --> 00:00:37,800 codes are oriented in these classes. 9 00:00:37,800 --> 00:00:42,600 Now classes are used in order to keep some of the related things together. 10 00:00:42,660 --> 00:00:49,140 I'll show you the most simple version of classes so you can actually get a brief understanding of what 11 00:00:49,140 --> 00:00:50,190 they actually are. 12 00:00:50,730 --> 00:00:53,200 So let us get right into it. 13 00:00:53,250 --> 00:00:57,450 So let's open up our part on an interpreter. 14 00:00:57,720 --> 00:01:06,120 And in order to actually set a class you just use the name class and then the name of the class itself. 15 00:01:06,120 --> 00:01:13,470 So the name of the class or Let's type your class person you specify the open brackets and then you 16 00:01:13,470 --> 00:01:15,810 specify two dots in that. 17 00:01:15,840 --> 00:01:20,220 So after that you need to specify everything in this class. 18 00:01:20,220 --> 00:01:25,780 So basically most of the classes will have something called self. 19 00:01:25,800 --> 00:01:33,240 Now it might be a little bit hard for you to understand that but you will need or you won't need but 20 00:01:33,300 --> 00:01:39,150 it is most likely going to you are most likely going to start the classes with the function called in 21 00:01:39,150 --> 00:01:39,540 it. 22 00:01:40,650 --> 00:01:46,590 Basically what this means is it will give all of the objects that are currently corresponded to this 23 00:01:46,710 --> 00:01:47,490 person class. 24 00:01:47,490 --> 00:01:55,080 So for now on lets us add the self object and the name object the name basically something is basically 25 00:01:55,080 --> 00:02:01,950 a name that this person will have and the s object is the object that we are going to refer to in the 26 00:02:01,950 --> 00:02:02,310 class. 27 00:02:02,340 --> 00:02:09,240 So let me explain it to a little bit better to you know so you can understand it basically well this 28 00:02:09,240 --> 00:02:15,840 will do is if I just type yourself not name equals name. 29 00:02:15,840 --> 00:02:21,390 This will put ourselves that name our name variable in self-taught name variable. 30 00:02:21,390 --> 00:02:24,590 Now this is something that you will see a lot in these classes. 31 00:02:24,600 --> 00:02:30,250 This is basically just the syntax for the python so you will need to get used to it. 32 00:02:30,420 --> 00:02:33,140 If I just type here enter you will see the thread. 33 00:02:33,150 --> 00:02:40,500 Now we have the class Person identified and we have it right here in Python interpreter in order for 34 00:02:40,500 --> 00:02:42,500 you to use this class person. 35 00:02:42,540 --> 00:02:49,590 Basically what you need to do is actually just type here the name or any variable so Person 1 or let's 36 00:02:49,590 --> 00:02:50,420 call it. 37 00:02:50,520 --> 00:02:59,400 Oh yeah let's call it Person 1 which is a variable equals and then we need to put the class that we 38 00:02:59,400 --> 00:03:00,620 want to put this person in. 39 00:03:00,630 --> 00:03:08,940 So class Person 1 We want to put him or her in the Person class and you can just type your person and 40 00:03:09,150 --> 00:03:14,580 presenter you will need to specify all the arguments that we specified in our class which in our case 41 00:03:14,640 --> 00:03:16,020 is only the name. 42 00:03:16,020 --> 00:03:19,640 So what we need to specify is the name so let's call him John. 43 00:03:19,650 --> 00:03:24,980 So under the quotes you just type your John and you can press here enter. 44 00:03:24,990 --> 00:03:29,400 So now we have a person one which is stored under the class person. 45 00:03:29,430 --> 00:03:36,710 So if you wanted to just type your person one you would see OK this is a memory object. 46 00:03:36,720 --> 00:03:42,630 So let me just show you it like this so print in order to print the person's name you will need to print 47 00:03:44,360 --> 00:03:51,300 person 1 which is our John and then dot and then we use the object we created in our class which is 48 00:03:51,300 --> 00:03:51,750 the name. 49 00:03:51,750 --> 00:03:57,660 So that is the only thing that we have in that class or print person that name and it will give you 50 00:03:57,720 --> 00:03:58,640 the John. 51 00:03:58,650 --> 00:04:05,230 So if you just type your person not print not prison but person to person. 52 00:04:05,240 --> 00:04:09,630 Now let's add that to the class as well and let's call her Jane. 53 00:04:09,840 --> 00:04:19,830 So person Jane and print person to not name we would get the name Jane and now both of these variables 54 00:04:19,950 --> 00:04:24,210 correspond to our correspondent to this class that we created. 55 00:04:24,210 --> 00:04:29,490 So that's what they mean by keeping the related stuff together with classes. 56 00:04:29,490 --> 00:04:31,620 Now this is the most simple use of it. 57 00:04:32,190 --> 00:04:39,870 Basically in this one we only had the variable name which we gave to our objects or basically to our 58 00:04:39,870 --> 00:04:42,670 variables Person 1 and Person 2. 59 00:04:43,020 --> 00:04:45,160 You can have multiple things. 60 00:04:45,330 --> 00:04:50,800 So let's see what we can do but let's close this interpreters since it's better to code our real program 61 00:04:50,820 --> 00:04:57,870 so Nan or Python 6 by and we start off with the usual things so fast to the python. 62 00:04:57,990 --> 00:05:03,920 And right now let's create the class which will store our name of a certain person and which will also 63 00:05:03,920 --> 00:05:06,980 store an email of that person. 64 00:05:07,010 --> 00:05:13,970 So that will be pretty similar to what we did in the previous thing but we also need to specify an email 65 00:05:14,240 --> 00:05:15,150 in our class. 66 00:05:15,170 --> 00:05:18,470 So let's call the class for example 67 00:05:21,140 --> 00:05:22,180 information. 68 00:05:22,640 --> 00:05:24,840 Let's call it like that doesn't even matter. 69 00:05:24,950 --> 00:05:32,420 And what we want to specify right there we want to specify or we actually want to leave it closed so 70 00:05:32,940 --> 00:05:39,960 don't type anything just type your two dots after the brackets and then presenter and we create the 71 00:05:39,960 --> 00:05:41,450 simple function as before. 72 00:05:41,450 --> 00:05:50,000 So the F def in its function we put the self right here and we put the name and email since that is 73 00:05:50,090 --> 00:05:56,180 what we want to actually have for every person we put in this class what you want to do right after 74 00:05:56,180 --> 00:06:02,370 that we want to do the same thing that we did before so self not name equals name self self-doubt the 75 00:06:02,390 --> 00:06:05,180 email equals e-mail. 76 00:06:05,510 --> 00:06:14,230 This will store both name and email in our class and right now all we have to do is basically just give 77 00:06:14,680 --> 00:06:21,700 or create a variable which will be corresponded to a person and put it in this class while also obtaining 78 00:06:21,700 --> 00:06:24,340 the name and the email for that person. 79 00:06:24,340 --> 00:06:26,830 So let's do that runs through right here. 80 00:06:26,830 --> 00:06:30,300 So let's call him Jack or let's call him. 81 00:06:30,430 --> 00:06:37,030 All right we can call him Jack equals and then we want to put him in a class we put that with just specifying 82 00:06:37,030 --> 00:06:42,760 the name of our class which is information which is probably not that good of a name for this class 83 00:06:42,790 --> 00:06:48,460 but it doesn't matter currently and we open brackets right here and what we want to do is just specify 84 00:06:48,850 --> 00:06:49,710 these two things. 85 00:06:49,710 --> 00:06:53,190 So the first thing would be name as we specified firstly. 86 00:06:53,230 --> 00:06:55,470 And the second thing would be email. 87 00:06:55,480 --> 00:07:00,890 So right now we open quotes first of all we specify Jack as a name. 88 00:07:01,180 --> 00:07:07,900 We put comma right here and then we specify the email so let's say it's Jack at gmail dot com. 89 00:07:09,010 --> 00:07:13,960 And that would be about it for the specification of the jack for this class. 90 00:07:13,960 --> 00:07:18,730 So all we have to do right now is if we want to print the information for Jack. 91 00:07:18,730 --> 00:07:25,690 You can just type your print Jack dot name and print Jack dot email. 92 00:07:26,680 --> 00:07:28,310 So that's how you can use this. 93 00:07:28,360 --> 00:07:34,210 Basically it is really simple though everyone seems to understand this. 94 00:07:34,210 --> 00:07:35,120 The hardest. 95 00:07:35,200 --> 00:07:35,960 I did too. 96 00:07:35,980 --> 00:07:42,730 But once you actually get used to this you will be this one really present that much of a problem to 97 00:07:42,730 --> 00:07:43,090 you. 98 00:07:43,090 --> 00:07:47,220 Classes can be a little bit tricky sometimes but they're not that hard to learn. 99 00:07:47,230 --> 00:07:53,100 So you just save this control or to save can enter and the control X to exit. 100 00:07:53,230 --> 00:08:01,000 Right now let's see page more dollar by six and run it six slips. 101 00:08:01,660 --> 00:08:08,350 And here we can see that when it prints out the name and email we get the jack and jack at gmail dot 102 00:08:08,350 --> 00:08:09,310 com. 103 00:08:09,460 --> 00:08:12,880 So that will be everything for classes. 104 00:08:12,880 --> 00:08:18,360 Now you can also stack classes one under another so class in a class in a class in a class. 105 00:08:18,370 --> 00:08:22,240 But that is the more advanced section basically. 106 00:08:22,630 --> 00:08:24,470 We won't be doing that right now. 107 00:08:24,490 --> 00:08:27,860 And we also don't need it for our coding or backdoor. 108 00:08:28,000 --> 00:08:30,370 So there is really no point in doing that. 109 00:08:32,180 --> 00:08:41,810 You can also use certain parts of the class in a print statement so let me just show you so you can 110 00:08:41,810 --> 00:08:50,900 see so you can just type your print the user's name is and then you just type here. 111 00:08:50,900 --> 00:08:56,120 The closed quotes and then plus and then jacked up name so you can do it like that. 112 00:08:56,120 --> 00:08:57,160 It doesn't really matter. 113 00:08:57,160 --> 00:09:02,300 So the plus we'll just add the string of this to the string right here that is specified. 114 00:09:02,300 --> 00:09:05,410 So this will specify the user's name is Jack. 115 00:09:05,480 --> 00:09:13,760 You can do the same here as well so the user's email is and then plus the string. 116 00:09:13,780 --> 00:09:16,170 So we say this once again. 117 00:09:16,170 --> 00:09:22,460 And if we run it you will see the user's name is Jack and the user's email is Jack at gmail dot com. 118 00:09:22,970 --> 00:09:27,490 So that is probably something else you didn't know which is that you can stack two strings together. 119 00:09:27,490 --> 00:09:31,440 So this is one string which is just the name which in our case is Jack. 120 00:09:31,610 --> 00:09:37,850 And this is the second string so it will just add the string to the end of this one and it will print 121 00:09:37,850 --> 00:09:39,860 out the string as a single string. 122 00:09:39,860 --> 00:09:43,000 So that's something useful to know. 123 00:09:43,010 --> 00:09:49,280 So that will be about it for this tutorial and in the next one I will show you how you can actually 124 00:09:49,280 --> 00:09:54,950 import libraries from the Python and also import your own libraries which is also useful and which is 125 00:09:54,950 --> 00:09:58,950 something that we will do in order to create our programs. 126 00:09:58,940 --> 00:10:04,550 Basically it's you would be having to type all of the things from the very beginning if you don't include 127 00:10:04,550 --> 00:10:06,040 any libraries. 128 00:10:06,170 --> 00:10:11,420 But luckily we have some of the libraries that other people coded for us that we can use in our own 129 00:10:11,420 --> 00:10:14,330 programs with just a little bit of effort. 130 00:10:14,360 --> 00:10:16,340 So that would be about it for this video. 131 00:10:16,820 --> 00:10:19,940 I hope you enjoyed it and I hope I see you in the next one. 132 00:10:20,240 --> 00:10:20,510 But.