Thursday, August 19, 2021

Day2 - Object oriented programming in Python

 Day2 - Object oriented programming in Python
OOP principles
1. Encapsulation
2. Abstraction
3. Polymorphysm
3. Inheritance
Reading concept
1. Read the book and write notes
2. Record what you learn on your phone
3. Prepare all the questions from the book you read
4. Write the answer to the question
5. Select the best question and take a test without a book.
What is class?
- Class is a collection of states and behaviors
to define a class, we have to use class keyword. 
<syntax>
class <classname>
  <states>
  <behaviours>
First understand the state. What is state?
-> State represents some value. State can be variable or constant.
Types of variables in python
There are 3 types of variables in python
1. Local variable
2. Instance variable
3. State variable
What is a local variable?
-> a variable which is declared inside the method (or function) is called local variable
-> local variable can access only within the method or function.
-> Local variable will be getting memory at the time of method execution.
-> Local variable will be destroyed once method execution is completed.

Create some question based on above definition.
1. What is local variable?
2. What is the scope of local variable?
3. How memory is allocated for local variable?
4. How memory is de-allocated?
Reading tips
Think how many questions can you create on the topic above?
2. Instance variable
-> A variable which is declared inside the constructor or inside the instance method by using self keywork is instance variable.
- Instalce variable gets the memory within the object 
- 'self' is a keyword which represent current class object
- Intance variable will be getting memory at the time of object is creating.
- Instance variable will destroyed once the object is destroyed.
Questions?
1. What is instance variable?
2. How instance variable gets the memory?
3. What keyword is used in instance variable?
4. When instance variable is de-allocated or destroyed?
What is static variable?
static/dynamic coding ..
i and j 
i=j; i<j; i>j ; multiple if, else if, nested if
decision/control statement
A variable which is declared inside the class or inside the static method by prefixing classname is static variable.
Q. When the static variable will be getting memory?
- at the time of class is loading
Q. When the static variable will be destroyed or de-allocated memory?
- At the time of class is unloading
Example to declare instance variable
self.a=10
MyClass.b = 20
Here,
name of the class is: MyClass
b is: name of variable
20 is: the value assigned to a variable
as we know, class is collection of state and behaviour. We just discussed about state, now we will discuss about behaviour.
What is behaviour?
- Next class
Reading, writing and implementing tacktics
1. Read the book first topicwise and write the notes on each topic
2. After completing reading and taking notes, close your book and write on a paper without looking at the book.
3. Now, record what you learn on your mobile phone topic wise without looking at the book.
4. Prepare questions and answer of the topic by looking at the book.
5. Now, prepare fews questons by summarizing your old questions
6. Write your answer and record the question and answer.



No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...