Learn Python OOP in under 20 Minutes

Indently
30 Aug 202418:31

Summary

TLDRIn this educational video, the concept of Python classes is explored through an analogy with blueprints for constructing a house. The class is introduced as a template for creating objects, with a focus on the 'microwave' class. Key elements such as class instantiation, initializers, and instance methods are covered. The video demonstrates how to define and use methods within a class, like 'turn on' and 'run', to simulate the functionality of a microwave. Additionally, the use of dunder methods for customizing operator behavior and string representations of classes is explained, highlighting the importance of classes in organizing code and enhancing functionality.

Takeaways

  • πŸ—οΈ Classes in Python serve as blueprints for creating objects, defining their structure and behavior.
  • πŸ”‘ The class keyword in Python is used to define a class, and class names follow the camel case convention.
  • πŸ”§ Instantiating a class creates an object, or an instance of that class, using the constructor (parentheses).
  • βœ… Type annotations are optional in Python and are used for code editor assistance, not for runtime functionality.
  • πŸ› οΈ Initializers, or the __init__ method, allow customization of each instance with specific information.
  • πŸ”„ The 'self' keyword in class methods refers to the instance of the class and ensures data sticks to the correct object.
  • πŸ”€ Methods within a class define the functionality of the objects, such as turning a microwave on or off.
  • πŸ”„ Dunder (double underscore) methods are special methods in Python classes that allow customization of built-in operations.
  • πŸ” The __add__ method is an example of a dunder method that can be defined to handle the addition of two objects.
  • πŸ“ The __str__ and __repr__ dunder methods provide user-friendly and developer-friendly string representations of objects, respectively.

Q & A

  • What is a class in Python?

    -A class in Python is a blueprint for creating objects. It defines the properties and methods that an object of that class will have.

  • Why are classes useful in Python programming?

    -Classes are useful because they allow for the creation of custom objects with specific properties and behaviors, promoting code reusability and organization.

  • What is an instance in the context of classes?

    -An instance is a specific object created from a class blueprint. It represents a unique object with its own set of attributes and behaviors as defined by the class.

  • How do you create a class in Python?

    -In Python, you create a class by using the 'class' keyword followed by the class name and a colon. The class name should follow the camel case convention, starting with an uppercase letter.

  • What is the purpose of the __init__ method in a class?

    -The __init__ method is a special method called a constructor in Python. It is used to initialize the attributes of a class when an object is created.

  • What does 'self' represent in a class method?

    -'self' represents the instance of the class and is used to access variables and methods within the class. It ensures that the data and methods belong to the correct instance.

  • How can you add functionality to a class in Python?

    -You can add functionality to a class by defining methods within the class. Methods are functions that belong to the class and can perform actions on the object's data.

  • What is a Dunder method in Python?

    -A Dunder method, short for 'double underscore' method, is a special method in Python classes that starts and ends with double underscores. These methods have special meanings and are called 'magic methods'.

  • Why is the string representation of an object important?

    -The string representation of an object is important because it provides a human-readable description of the object, which is useful for debugging and logging.

  • How can you customize the way an object is displayed when printed?

    -You can customize the way an object is displayed when printed by defining the __str__ method in the class. This method should return a string that represents the object.

  • What is the difference between __str__ and __repr__ methods in Python classes?

    -The __str__ method should return a user-friendly string representation of the object, while the __repr__ method should return a developer-friendly representation that could be used to recreate the object if possible.

Outlines

00:00

πŸ“˜ Introduction to Python Classes

The video begins with an introduction to Python classes, explaining that a class acts as a blueprint for creating objects, similar to a house blueprint. The instructor uses the analogy of a microwave manufacturer to illustrate how classes can be used to design and create objects with specific attributes. The class is initially empty but can be used to instantiate objects, such as a microwave with the brand 'Smeg'. The video also touches on type annotations, which are helpful for code editors but not necessary for the code to function.

05:02

πŸ”§ Customizing Classes with Initializers

The second paragraph delves into customizing classes with initializers. The instructor demonstrates how to use the `__init__` method to create instances of a class with specific information, such as brand and power rating. This allows each microwave instance to have unique data. The concept of 'self' is introduced as a reference to the current instance of the class, ensuring that data sticks to the correct object. The paragraph also mentions the flexibility of renaming 'self' to other variable names, although it's not recommended due to Python conventions.

10:03

πŸ›  Adding Functionality with Methods

In the third paragraph, the focus shifts to adding functionality to classes through methods. The instructor creates methods like 'turn_on' and 'turn_off' to manipulate the state of the microwave object, introducing a 'turned_on' attribute to track the microwave's state. A 'run' method is also added to simulate the microwave's cooking function. The video shows how these methods can be used to interact with the microwave objects, providing a practical demonstration of object-oriented programming in Python.

15:04

πŸ”„ Exploring Dunder Methods for Custom Operations

The final paragraph explores dunder (double underscore) methods, which allow for custom behavior when using operators with class instances. The instructor demonstrates how to define the addition operator to combine two microwave objects into a 'fusion' of their brands. Other dunder methods like `__mul__` for multiplication and `__str__` for string representation are discussed, showing how they can be customized to provide user-friendly or developer-oriented information. The video concludes with a summary of the benefits of using classes to organize code and the ease of reusing functionality across different instances.

Mindmap

Keywords

πŸ’‘Class

In the context of the video, a 'class' is a blueprint for creating objects in Python. It defines the structure and behavior that objects of that class will have. The video uses the analogy of a house blueprint to explain that classes contain all the necessary information for what an object should do and how it should look. For instance, the script mentions creating a 'Microwave' class, which serves as a template for all microwave objects, detailing their attributes and methods.

πŸ’‘Object

An 'object' in the video refers to a specific instance of a class. It is created using the class blueprint and represents a unique entity with its own set of attributes and behaviors. The video script exemplifies this by creating 'Smeg' and 'Bosch' microwaves, which are objects instantiated from the 'Microwave' class, each having its own brand and power rating.

πŸ’‘Blueprint

A 'blueprint' in the video is used metaphorically to describe the role of a class in programming. It is a detailed plan that outlines the structure and functionality of something before it is built or implemented. In the context of the video, a class acts as a blueprint for objects, just as a house blueprint outlines the design of a house. The script explains that classes contain all the relevant information for what an object should do.

πŸ’‘Camel Case

In the video, 'camel case' is mentioned as a naming convention for class names in Python. It is a style where each word in a phrase starts with a capital letter and has no spaces or separators. The video script specifies that class names should follow camel case, as seen when the 'Microwave' class is named, adhering to the convention by starting with an uppercase letter.

πŸ’‘Initializer

The 'initializer' in the video refers to the __init__ method in Python classes, which is used to initialize the attributes of a class when an object is created. The script explains how to use the __init__ method to customize each microwave object with specific information like brand and power rating, making each instance unique.

πŸ’‘Self

In the video, 'self' is a reference to the current instance of the class and is used to access variables that belong to the class. It is a convention in Python to use 'self' as the first parameter of a method to refer to the instance. The script demonstrates using 'self' to set and access the brand and power rating of the microwave objects.

πŸ’‘Method

A 'method' in the video is a function defined within a class that performs certain actions or computations on the object's data. The script introduces methods like 'turn_on', 'turn_off', and 'run' for the 'Microwave' class, which allow the objects to perform actions like turning on, turning off, and running for a specified time.

πŸ’‘Type Annotation

In the video, 'type annotation' refers to a feature in Python that allows developers to explicitly specify the data type of variables. The script mentions that the variable 'Smeg' is annotated with the type 'Microwave', which helps code editors and IDEs understand the type of object 'Smeg' is expected to be, although it's optional and not required for the class to function.

πŸ’‘Dunder Method

A 'dunder method' in the video stands for 'double underscore' method, which are special methods in Python classes that have a name prefixed and suffixed by double underscores. The script discusses how to define operations like addition and string representation for the 'Microwave' class using dunder methods such as __add__ and __str__, respectively.

πŸ’‘Instance

An 'instance' in the video is an individual object created from a class. The script uses the term when explaining how to create a 'Smeg' microwave, which is an instance of the 'Microwave' class. Each instance has its own set of attributes and can have methods called on it, as demonstrated with the 'Smeg' instance being turned on and off.

Highlights

Classes in Python are introduced as blueprints for objects, similar to a house blueprint.

A class is defined using the 'class' keyword followed by the class name in camel case.

Instantiating a class creates an object, or instance, from the class blueprint.

Type annotations are mentioned as optional but useful for code editors.

Initializers, or constructors, are used to add specific information to instances.

The 'self' keyword is used to reference the instance within the class methods.

Methods are functions within a class that give the object functionality.

Demonstrates creating a 'turn on' method for the microwave class.

Shows how to create a 'turn off' method to complement the 'turn on' method.

Introduces a 'run' method to simulate the microwave cooking process.

Explains the concept of Dunder methods and their role in defining operations on objects.

Demonstrates defining the 'add' Dunder method to combine two microwave instances.

Covers the 'mul' Dunder method for multiplying instances, returning a custom string.

Discusses the 'str' Dunder method for user-friendly string representation of objects.

Differentiates between the 'str' and 'repper' Dunder methods for user and developer readability.

Concludes by emphasizing the organizational benefits of classes in Python for code functionality.

Transcripts

play00:00

this video was brought to you by IND

play00:02

dentle IO learning python Made Simple

play00:05

how's it going everyone in today's video

play00:07

we're going to be learning about classes

play00:09

in Python what they are and how we can

play00:12

use them but before we do anything I'm

play00:14

just going to explain a bit of the

play00:17

theory and to keep it simple a class is

play00:20

just a blueprint for what an object

play00:23

should look like and how it should

play00:25

function for example before you build a

play00:27

house usually you would create a

play00:29

blueprint containing all the relevant

play00:31

information and functionality regarding

play00:33

how that house should look and how it

play00:35

should function before you start

play00:37

building it and classes are no different

play00:40

they contain all the relevant

play00:42

information for what an object should do

play00:45

so for this lesson we're going to

play00:46

pretend that we are a microwave

play00:48

manufacturer which means first we're

play00:50

going to design the blueprint and then

play00:52

we're actually going to create the

play00:54

microwaves using that blueprint now in

play00:57

Python if you want to create a class you

play00:59

use the class keyword followed by the

play01:02

class name and the class name

play01:04

conventionally should follow camel case

play01:07

which means it will start with uppercase

play01:09

and every additional word will also

play01:12

start with uppercase so if you had a

play01:15

class called blue car you'll see that

play01:18

each time you have a new word it starts

play01:20

with an uppercase character but in this

play01:22

example we're going to call it microwave

play01:25

and for now it's going to be empty but

play01:27

already with this code we can start

play01:29

creating objects from this class because

play01:31

now we have the blueprint which means

play01:33

that we can actually get started with

play01:35

creating some microwaves so here what

play01:37

we're going to do is instantiate a

play01:41

microwave and to do that we're going to

play01:43

create a variable called Smeg which is a

play01:46

brand or a type of microwave you can

play01:48

search it on Google it's a very nice

play01:49

brand and that's going to be of type

play01:52

microwave which will equal the

play01:55

microwave with the Constructor which are

play01:57

these parentheses once you use the

play01:59

parenthesis on a class this creates an

play02:02

instance of that class which means we're

play02:04

creating a unique microwave from this

play02:08

blueprint also it's worth mentioning you

play02:10

did not have to include this bit here

play02:12

this is what they refer to as a type

play02:14

annotation or a type hint it's only used

play02:17

for code editors so if you don't like

play02:20

type annotations you can safely ignore

play02:22

that in all my videos I use type

play02:25

annotations because I find them very

play02:27

useful and I will use them throughout

play02:29

this lesson as well but it's up to you

play02:31

whether you want to include type

play02:33

annotations or not in your code anyway

play02:35

now we have an instance of a microwave

play02:38

which is called smag which means if we

play02:40

were to print this what we're going to

play02:43

get back is a unique ID pointing to the

play02:46

unique instance of this microwave but as

play02:49

it stands this class is kind of useless

play02:52

it doesn't contain any useful

play02:53

information nor functionality so next

play02:56

we're going to modify it because we want

play02:58

our microwaves to be be a bit more

play03:00

customizable so next we're going to be

play03:02

learning about initializers how to

play03:05

create instance with specific

play03:07

information which actually kind of

play03:10

customizes each one of the microwaves

play03:12

that we create so here we're going to be

play03:14

using a Dunder method called init and by

play03:17

default init returns none you're not

play03:20

required to provide this I just like to

play03:22

do it with all my code because it makes

play03:24

it extra explicit the initializer takes

play03:27

care of initializing the class which

play03:30

means if you have any extra information

play03:31

you want to give the class when you are

play03:33

creating an instance that code is going

play03:36

to be run here as soon as you

play03:38

instantiate it so right after Self we're

play03:41

going to type in brand of type string

play03:44

and power rating of typ string and

play03:47

inside here we need to type in self.

play03:49

brand equals brand and self. power

play03:53

rating equals power rating and

play03:55

immediately we're going to get some

play03:56

syntax highlighting because we need to

play03:58

now provide this information

play04:00

to the

play04:01

Constructor so here we're going to give

play04:03

it the brand of

play04:05

Smeg and we're going to give it a power

play04:08

rating of B and thanks to this

play04:11

information we now have a microwave that

play04:13

actually contains some data so if we

play04:16

were to print sm. brand and sm. power

play04:21

rating you'll see that this class will

play04:23

contain that information it's going to

play04:25

return to us the information that we

play04:27

inserted and we can even create another

play04:29

mic microwave which we're going to call

play04:31

Bosch or

play04:33

bch and that's going to equal this

play04:36

microwave with the brand set to Bosch do

play04:39

let me know in the comment section down

play04:40

below how much I'm messing that up and

play04:44

the power rating will be set to C then

play04:47

we can print bch do brand and the power

play04:52

rating and what we should get is the

play04:54

information from Bosch now but right now

play04:57

you're probably asking okay that makes

play04:59

sense but what is self you completely

play05:02

skipped self well self is the actual

play05:05

instance of the class and that just

play05:07

makes sure that all this data sticks to

play05:11

the correct instance or to the correct

play05:13

object in the case of smag as soon as we

play05:15

insert this information self turns into

play05:21

smag so all of these become smag but

play05:25

that's only when we're referring to smag

play05:27

otherwise if we're referring to bch

play05:31

this becomes bch which means when we

play05:34

call b. brand it gives us the correct

play05:37

data back so again self just refers to

play05:40

whichever instance we're currently using

play05:42

and one thing that's quite cool that a

play05:44

lot of beginners don't know about is

play05:46

that you can actually change this name

play05:47

to whatever you want you can even change

play05:49

it to this which is something popular in

play05:51

Java or you can change it to something

play05:54

called

play05:55

instance if that's what you want you can

play05:57

do it I do not recommend you do that

play06:00

because conventionally we will always

play06:02

have this as self if you look at other

play06:04

tutorials or you look at documentation

play06:06

online this will always be referred to

play06:08

as self but it's just a convention so if

play06:11

you really want to change this to

play06:12

something else you can do that and the

play06:14

code will function the same I mean you

play06:16

can even change this to S and if we run

play06:19

the code it's going to work exactly the

play06:21

same way next let's move on to the topic

play06:24

of methods because right now we have a

play06:27

microwave that contains data but it

play06:29

doesn't do anything it doesn't function

play06:31

so what I'm going to do is remove all of

play06:33

this we're still going to keep Smeg

play06:35

because I want to use it later but the

play06:36

rest we're going to

play06:38

delete and inside here we're going to

play06:40

create our very first method which is

play06:42

going to be called turn on because we

play06:46

want to be able to turn on the microwave

play06:48

and that's going to return none because

play06:49

this will only execute code and I also

play06:52

forgot but inside the initializer we

play06:54

want to add another attribute and this

play06:57

one's going to be called turned on so we

play06:59

can follow or track the state of the

play07:02

microwave whether it's turned on or off

play07:04

and this will be of type Boolean and

play07:06

it's going to be set to false initially

play07:09

so as soon as we create a microwave

play07:11

we're going to make sure it's turned off

play07:13

as soon as we use it I mean imagine you

play07:15

open a box with a microwave and it's

play07:17

already turned on that would be kind of

play07:18

weird anyway now that we have that

play07:20

attribute we can refer to it by typing

play07:22

in if self. turned on so if it is turned

play07:26

on we're going to print the following

play07:28

statement microwave and inside here I

play07:30

want to add the brand self. brand is

play07:32

already turned on so we don't turn on

play07:35

that microwave twice else we're going to

play07:38

set self. turned on to true and we're

play07:42

going to inform the user that we

play07:43

successfully turned it on so we'll copy

play07:46

this paste it down here and say that the

play07:48

microwave with the selft brand is now

play07:51

turned on and that will be our very

play07:54

first method but next I want to copy

play07:57

this and paste it directly under because

play07:59

we're going to create a function that

play08:00

turns off the microwave so we're going

play08:03

to rename that to turn off and this time

play08:06

if the microwave is turned on we're

play08:07

going to do the exact opposite we're

play08:09

going to set self do turned on to false

play08:13

and we're going to kind of flip these so

play08:15

I'm going to or actually to make this

play08:17

much easier I'm going to remove

play08:18

everything so we don't mix it up and

play08:22

just copy the statements from above so

play08:24

now we can type

play08:26

in that this is now turned off else if

play08:31

we try to turn off a microwave that's

play08:32

already turned off we're going to give

play08:35

them a statement that says the microwave

play08:37

is already turned off and finally I'm

play08:41

going to provide one more method for

play08:43

this class and this is going to be the

play08:45

run method so we can actually put food

play08:47

inside and give it a timer and cook that

play08:50

food so here we'll say run for this

play08:54

amount of seconds which will be of type

play08:56

integer and once again that will return

play08:58

none and obviously we first need to

play09:00

check if self. turned on is set to True

play09:03

otherwise we can't run the microwave but

play09:06

if it is we can print that we are

play09:08

running self. brand for seconds seconds

play09:14

else we're going to

play09:17

print that a Mystical Force Whispers

play09:21

turn on your

play09:23

microwave first and those will be the

play09:26

methods that we will use for this class

play09:29

now we can actually turn on the

play09:30

microwave we can turn off that microwave

play09:32

and we can run the microwave as you can

play09:34

see we have a full blueprint of what the

play09:36

class should look like and how it should

play09:38

function so next let's try to use this

play09:40

functionality so right below our

play09:43

instance of Smeg we're going to refer to

play09:46

it and use dot notation to actually use

play09:49

these methods so right now we're going

play09:51

to turn on the microwave twice and what

play09:54

you're going to notice in the console is

play09:56

that the first time it's actually going

play09:58

to turn it on but the the second time

play10:00

it's going to tell us that it's already

play10:01

turned on so we have that safety

play10:02

mechanism in place but once it's turned

play10:05

on we can refer to Smeg and run this

play10:08

microwave for let's say 30 seconds or

play10:12

yeah 30 seconds and then we will turn

play10:14

off the

play10:15

microwave and now if we run it you'll

play10:17

see that the microwave will turn on it's

play10:19

going to run for 30 seconds and then

play10:21

it's going to turn off because that's

play10:23

exactly what we told it to do if we try

play10:26

to run our microwave after we've turned

play10:28

it off for 10

play10:30

seconds we're going to get that Mystical

play10:32

Force that Whispers to us that we should

play10:34

turn on our microwave first so as you

play10:36

could see it was that easy to give our

play10:38

class functionality and data that we

play10:40

could later use to execute certain

play10:43

functionality and what's really cool

play10:44

about this is that no matter what

play10:46

microwave we

play10:48

create we can use all of that

play10:51

information the same way which means

play10:54

here we're going to change it back to

play10:56

bch give it a power rating of C and now

play10:59

with B we can perform the same actions

play11:02

we can turn it on we can turn it

play11:05

off and we can try to run it for let's

play11:08

say 2

play11:09

seconds and it's going to work exactly

play11:12

the same way microwave buch is now

play11:14

turned on and then it turns off and then

play11:17

the Mystical Force Whispers to us that

play11:18

we can't run it without turning it on

play11:20

first so with that minimal setup we

play11:23

could use all the functionality once

play11:25

again but there's still one last thing I

play11:27

want to show you before we conclude this

play11:29

video and this is the concept of Dunder

play11:32

methods so for the next example I'm

play11:34

going to remove all of this and keep

play11:37

both of these microwaves so that we can

play11:39

use them later also in pycharm I'm going

play11:41

to collapse these methods because you

play11:43

already know what they contain so that

play11:45

we have some more space on our screen

play11:48

but now that we have all of this space

play11:49

on our screen I can finally get started

play11:51

with explaining how Dunder methods work

play11:54

in Python and to explain it I'm going to

play11:58

attempt to perform this operation which

play12:00

is Smeg plus bch if you try to run this

play12:04

you'll immediately notice that we will

play12:06

get back a type error that we tried to

play12:08

use this operand with these objects and

play12:11

that was not supported because we did

play12:13

not Define this operation anywhere in

play12:15

our class but to Define it what we need

play12:18

to do is go inside our class and Define

play12:20

a Dunder method so here we're going to

play12:23

use the dunder method called add which

play12:25

will take self which is the current

play12:27

instance and which is the other instance

play12:31

and the reason they call this thunder

play12:32

method is because they have double

play12:35

underscores so it's actually a double

play12:37

uncore method and you might also hear

play12:40

these being referred to as magic methods

play12:42

anyway as soon as you supply this thund

play12:45

method the syntax highlighting will go

play12:48

away and the warning will go away as

play12:50

well right now if I don't add anything

play12:53

here the script will run but it's not

play12:55

going to return anything so adding these

play12:58

together will do nothing but inside here

play13:01

you can actually do whatever you want

play13:03

you can make it return whatever you want

play13:06

if you add one microwave to another you

play13:08

might expect to get a fusion back and in

play13:11

this example we can return a string with

play13:14

self. Brand Plus other do brand so that

play13:19

when we actually try to add these

play13:21

together what we will get back is this

play13:24

Fusion and the same thing applies for

play13:26

the other operators whether it's an

play13:29

asterisk or a pipeline or whatever all

play13:32

of these can be defined in our class so

play13:34

if we want to Define for example the

play13:36

multiplication operator we can do that

play13:38

using the dunder mole

play13:41

method and here we can

play13:44

return exactly the same thing from

play13:46

earlier except with an asterisk as you

play13:49

can see now the next time we actually

play13:51

call this it's going to give us back the

play13:53

string that we specified and you don't

play13:55

have to return a string here you can

play13:57

actually return whatever you want it can

play13:59

even be another instance of the class

play14:01

but one that's actually very useful is

play14:04

the string Thunder method and this is

play14:07

going to return to us a string and what

play14:09

we will return is the F string of self.

play14:14

brand

play14:15

parenthesis with the rating set to self.

play14:20

power rating and what this does is give

play14:23

us a legible string representation of

play14:26

our class so that the next time we

play14:28

actually print any one of our classes we

play14:31

will get back something that we can

play14:32

actually read and if we do this with bch

play14:36

we will also get something legible for B

play14:39

otherwise without this Stander method

play14:41

we're going to get the memory address of

play14:43

the class or the representation of the

play14:46

class and that's also something that you

play14:48

can override for example if we go here

play14:51

and we Define the representation this

play14:54

will return to us a string so here

play14:57

instead of returning that memory address

play14:59

you can return whatever you want this

play15:00

will be used when you use the

play15:02

representation of the class so if you

play15:04

use repper on Smeg or repper on B it's

play15:07

going to use this thunder method but you

play15:09

might be asking if we had none of these

play15:11

defined why do we get this back for the

play15:14

representation well that's because

play15:16

that's the default representation for a

play15:19

class when you print an object if it

play15:21

can't find the string Dunder method it's

play15:23

going to use the representation that's

play15:26

why when we use the string

play15:27

representation it's going to fa to using

play15:29

the string representation and one thing

play15:31

I want to mention very fast because I

play15:33

know this will confuse a lot of people

play15:34

when they are learning python but the

play15:36

difference between the string Dunder

play15:38

method and the reer dunder method is

play15:40

that the string Dunder method should

play15:41

return something that is user friendly

play15:44

something that your grandmother could

play15:46

read while the representation Dunder

play15:48

method should return something that's

play15:50

useful for the developer for example

play15:53

here we have a microwave class so

play15:54

something you could return is the

play15:57

microwave with the following arguments

play16:00

which we have brand and power rating so

play16:02

brand can equal self. brand and power

play16:07

rating will equal the self. power rating

play16:10

and both of those are strings so I will

play16:11

surround those in quotation marks this

play16:13

is a good example of something you can

play16:15

return in the rapid under

play16:18

method because right now when we run

play16:20

this we're going to get the userfriendly

play16:21

message but as soon as the developer

play16:24

asks for something more specific such as

play16:27

what this object actually is what they

play16:29

will get back is this representation of

play16:32

the object and I absolutely messed that

play16:34

up because the quotation mark should be

play16:37

inside the parenthesis this actually

play16:39

gives information that's useful for a

play16:41

developer because now they know that you

play16:43

have a microwave object with a brand set

play16:46

to this string and a power rating set to

play16:49

this

play16:50

string while the string

play16:52

representation only gives us something

play16:54

legible but if we change that to repper

play16:57

as well

play16:59

we'll get the same thing back anyway

play17:02

it's time to conclude this video with

play17:04

answering the question why all this hard

play17:06

work well in certain situations classes

play17:10

can be seen as the best way to organize

play17:12

your code in the sense that all the

play17:14

functionality is coupled with the class

play17:17

so you will have everything you need in

play17:19

one place and that just makes it easy to

play17:21

create functionality that actually works

play17:23

with minimal effort just like I

play17:26

demonstrated with these two microwaves

play17:29

we can even add a third one called

play17:30

Samsung which will be of type microwave

play17:33

that's going to equal a

play17:34

microwave with the brand set to Samsung

play17:38

and the power rating set to a and just

play17:41

like that we can use all of that

play17:42

functionality with Samsung we can turn

play17:44

it on we can run the microwave for 1

play17:48

second and then we can turn it off and

play17:50

that will run straight out of the box it

play17:53

was that simple to set up a microwave

play17:55

and then use it with no further issue

play17:58

which is just just very convenient

play18:00

because if we did not use a class for

play18:02

these microwaves we would have to go

play18:04

through a lot of effort to create

play18:06

separate microwaves so yeah that's

play18:08

actually all I wanted to cover in

play18:10

today's video do let me know in the

play18:11

comment section down below what you

play18:13

think about classes whether you're

play18:15

confused about something or whether

play18:17

there's something I should have covered

play18:18

in more detail please let me know in the

play18:20

comment section down below and I'll try

play18:22

to make a followup video or I will learn

play18:24

from my future lessons but otherwise

play18:26

with all that being said as always

play18:28

thanks for watching and I'll see you in

play18:30

the next video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Python ClassesObject-OrientedProgramming TutorialMicrowave ExampleCode OrganizationClass FunctionalityData CouplingSoftware DevelopmentEducational ContentPython Programming