We have seen the basics of Object oriented programming(OOPs) now in this blog we will go through the Types of variable used in implementation of OOPs .
Types of Variables in OOPs:
There are three types of variable:
1) Instance Variable
2) Static Variable
3) Local Variable
1) Instance variable:
In above example person_1 and person_2 object has been created, these object has different variables and these variables vary as object to object.
Like person_1 name is Prashant occupation is Sr.engineer but person_2 name is Vishal occupation is Sr.developer. As we start adding object name of people changes, these type of variables called instance variable.
We define these variable under constructor __init__(self), also we can define them other ways but for intro purpose this is ok I guess.
any variable with "self. " is instance variable in constructor we can give any name.The mentioned variable in constructor are temporary to load the value.
2) Static variable:
========================================
Suppose the object person_1 and person_2 belong to same community or state or nation or company hence in this case the community name or state name or name of the nation is same means all object we have created has one or many things in common in that case we can define such variable just after the class created and hence this variable also called as class variable.
You can access these variable using any object person_1.nation for particular object or can access using class name People.nation it will give you same results. in above code we used Community static variable when you run this code you will get same result.
3) Local Variable:
The variable used in method for temporary requirement known as local variable or method variable.
References:
====================
Code with harry YouTube channel
Durga sir classes YouTube
Python basics for beginner Udemy course