Hi everybody.
Welcome back.
In this video we will discuss object oriented programming.
What will be the second interactive constructor method.
A class can define missile with special name these names begin and end with a double under this code
one in both and its natural name is underscore underscore and it underscore underscore its the for the
class at school.
Each time an instance of the class is created and implementing these missiles in a class gave us a chance
to initialize each instance of our class we will use geometry notebook for coding a class of user that
I have the init miss which is constructor and two parameters.
Suppose it will be a name and age of the user.
So we will initialize our variable age and the name as follows.
Class
C L A S S user data in camel case.
So user the first letter U capital and that is the first letter is d capital a member enters its close
parentheses column enters H equal zero and the name equal none
then where it was and will use the z defined method to create the class buddy
define def
double underscore and it doubled under a school
self
name and H
column enter self
that name a quote name
and self the H
equal H.
Finally we will use defined methods to call the class via its any census
define
define the same level of either indentation of a Z fairness to defined method
use as
self
then we will type Brent for example user name sorry user with capital U user
name
is
two curly brackets
and there has
to cut the brackets is
all full stop.
Then double quotes that for me.
Self
the name
and self that age.
We will add users to this class.
User 1.
Equal.
As we explained in the last lecture users data
Robyn.
But entities close but entities Sara
comma 40 and enter 5 different users as follows.
Two will be for example davit
and 50
three will be for example
John
and 30
user four will be gate
and twenty
user five.
For example will be beta
and 14 Zen shift and enter Zen we will check type of users.
1 will be mean user data.
This means that there is a part of a class called User that the same for the rest of users.
Then we will check user to not its
shift and enters.
We will get 15
users 3 that name we will get zone
Suppose we want to calculate their users average age we will create a function will do that.
Def AVC under school age
of.
But entities close parentheses column retarded.
Use it one
dot age for less
user
to dot age plus users 3.
What age.
The last user for that age plus users.
5 that age
sorry retarded
to retain user 1 that age user to that age user 3 that age user forwarded to the age user 5 that age
divided by 5 the number of users.
Then we will call that function AVC
underscore it.
We will get seventy one so as average age of the users is 71.
Also we can get more information from our class as follows.
User 1 that user.
The second function in our class.
Click shift and enter.
We will get user name is Sara and has 40 years old so can get any information from our class through
its body and its tenses and defining methods.
We will define an asset class called rectangle and throw it any senses.
We will calculate the area of the rectangle throw the defined method.
See a s s Rick can tango
enter if double underscore in it.
Now it underscores self
length
and why it's
called on self that length
equal length.
Self-doubt lends equal lengths so we will be fair and instances too as the parameters of saying it misled.
Also for the lights
it was a rectangle
then to find another missile.
Yes.
Rex area which is a buddy of Zachary glass rectangle.
We will use to calculate the area of the rectangle self.
The same instance of the class
created
self.
Docklands
multiply by self that wife.
Then we will define our rectangles rect underscored one equal break.
Tango class
Rick
rectangle
rectangle class
30 and 50
rect 1 rectangle 1 equal rig.
Tango class 50 and 30 then rectangle 2 equal rectangle
140 and 60.
Rick Stengel 3 equal rectangle.
Class
120 and 17 rectangle 4
equal rectangle
and 80 shift and enters and check for rectangle 1.
That depth lends reacts Varia or whites.
We will check for lengths collection and enter.
We will get 50 rectangle 2.
For example
to dot tab check for whites.
We will get 60 tangle underscores three rect underscores we got there.
We will get uh three choices.
We will choose rect area shift and enter
boundaries of the rectangle.
That area mean this because we don't edit the open and close parentheses of Z results.
We will get 8 7 and 4 handle it.
Then we will check for rectangle for
diet
type of minute.
This is a rectangle 4 x 4 close parenthesis shift and enters an not rectangle.
This means that rectangle 4 is a part of rectangle plus.
Suppose we want to get the average area of all rectangles.
We will type Brent of Amber entities req underscore one dot tap rect area but it is this close parenthesis
to that act underscore fourth from rect underscored one to select underscores divided by the number
of rectangles that we have in our class we will get six thousand five hundred seventy five.
Thank you for watching.
See you next lecture.