Basic Class and Object

Lets start with basic example of banker problem to understand basic class and object Assume you want to create an account in SBI bank. So you fill that form and your account is created. Now you are the person who created that form. Which attribute or field you will create which is necessary to create an account. Lets say:- Name DOB Aadhaar card no. PAN Card no. class BankForm: def __init__(userName,userDOB,userAdhaarNo,userPAN): Name=userName DOB=userDOB AdhaarNo=userAdhaarNo PAN=userPAN Rohan=BankForm("Rohan","12-09-2025","xxxx8907","KB1234") print(my_car) you will find an error. why? Because the class doesn't know about the form. It mean that you are creating the form, but for whom. If you are thinking for SBI. Let me tell you they doesn't know. so how we are going to tell them. By using 'self'. class BankForm: def __init__(self,Name,DOB,AdhaarNo,PAN): self.Name=Name self.DOB=DOB self.AdhaarNo=AdhaarNo self.PAN=PAN Rohan=BankForm("Rohan","12-09-2025","xxxx8907","KB1234") print(my_car.Name) 'self' it just a way to tell SBI I have a form for you. Now you have heard some word like Instance, __init__ and object. Instance:- It is just like Rohan want form for himself.So you have to fill BankForm as in Instance. __init__:- Initialisation of object. Like you want to create form and decide field which is needed for the form. Like Name, DOB, AdhaarNo., PANNo.. Object:- simply it is the field.

May 4, 2025 - 12:01
 0
Basic Class and Object

Lets start with basic example of banker problem to understand basic class and object

  1. Assume you want to create an account in SBI bank. So you fill that form and your account is created.
  2. Now you are the person who created that form. Which attribute or field you will create which is necessary to create an account. Lets say:-
  • Name

  • DOB

  • Aadhaar card no.

  • PAN Card no.

class BankForm:
def __init__(userName,userDOB,userAdhaarNo,userPAN):
Name=userName
DOB=userDOB
AdhaarNo=userAdhaarNo
PAN=userPAN

Rohan=BankForm("Rohan","12-09-2025","xxxx8907","KB1234")
print(my_car)

you will find an error. why?

Because the class doesn't know about the form. It mean that you are creating the form, but for whom. If you are thinking for SBI. Let me tell you they doesn't know. so how we are going to tell them.

By using 'self'.

class BankForm:
def __init__(self,Name,DOB,AdhaarNo,PAN):
self.Name=Name
self.DOB=DOB
self.AdhaarNo=AdhaarNo
self.PAN=PAN
Rohan=BankForm("Rohan","12-09-2025","xxxx8907","KB1234")
print(my_car.Name)

'self' it just a way to tell SBI I have a form for you.

Now you have heard some word like Instance, __init__ and object.

Instance:- It is just like Rohan want form for himself.So you have to fill BankForm as in Instance.
__init__:- Initialisation of object. Like you want to create form and decide field which is needed for the form. Like Name, DOB, AdhaarNo., PANNo..
Object:- simply it is the field.