Welcome back, everyone, to this series of lectures where we're going to be discussing the details
of object oriented programming and part one, we're just going to have a slide based overview of the
syntax structure.
So Opie, or object oriented programming allows programmers to create their own objects to have methods
and attributes.
Recall that after we defined a string or list or dictionary or other data type objects in Python, you
were actually able to call methods offer them with the DOP method name syntax.
And these methods act as functions that use information about the object to return results or change
the current object.
For example, this includes a pending an item to a list or counting the occurrences of an element and
a tuple.
OPI allows users to create than their own objects.
The syntax format, however, is often confusing when it's first encountered.
And also, if you're a beginner in Python, you've only used functions so far.
Sometimes it's a little confusing of why it's actually useful to define things as a class in an object.
But in general, object oriented programming allows us to create code that is repeatable and organized.
And more importantly, it's a feature that Django uses quite often, so we do need to understand it.
For much larger scripts of Python code, functions by themselves usually are enough for organization
and repeatability, and commonly repeated tasks and objects can be the of up to create code that is
more usable and readable.
So let's check out the general syntax with a simple example.
So here I have a very simple example of a object oriented programming approach to creating your own
object using class.
So let's go through the main parts of this actual code.
So at the top, in a similar fashion to the way you use the ADF keyword to define a function, you use
the class keyword to define a class or object in Python.
And notice by convention classes use camel case instead of a snake case.
That way, when you're actually calling them in your code, you can tell whether using a function or
a class.
Then there is the in it call, which is the instantiation or initialization call for the actual class.
This is going to help define what parameters or arguments you need to actually pass into the class when
you create a new instance of the class and notice the actual syntax here.
You're going to end up actually passing in parameters and then you're going to use what's known as the
self keyword to assign them to that particular instance of the class.
So here what we're saying is we're passing in some value for parameter two, and then I'm assigning
that parameter to the actual class by saying self-report parameter to essentially linking it to that
particular instance of the class.
So Param two is what the user passes in and self that Param two is, then how we define it and link
it to an instance of the actual class.
And that after that, we can define as many methods as we want.
So these look a lot like functions, but they're inside the actual class call and we can see that the
functions can perform any sort of action they want.
They can also take in their own parameters.
Here we have a very simple method call.
And when we actually have these inside the classes, we won't really be calling them functions.
Instead, we'll call them methods in the class or the act on the class.
Here, this one's really simple.
It just is going to print out parameter one.
You will also notice that it takes in the self keyword argument that lets Python know that this is a
method that can use information of the instance of the class, allowing it to actually call self-taught
param one.
In this case, it's actually just printing it out.
So what we're going to do in the next lecture is actually explore object oriented programming and a
lot more detail of code, and we'll start building out some very basic examples.
And then we're going to add more and more topics like inheritance and special methods later on in future
lectures.
OK, I'll see you at the next lecture, or we begin actually cutting out our first O.P. classes.