📎 Referral Code:
—
📊 Dashboard
Sign In
Regular
Python
Live Classes
Courses
Assignments
Q & A
My Profile
Recruiter Board
Job Support
Career Preparation
🎯
Interview Board
Real Q&As from top companies
Popular
Placement Support
🧑
Interview Support
Check Interview or Documents
Available
Class Room
AI Tools
AI Agents
🌐
Project Explanation Agent
Find tutorials & docs instantly
New
Support Works
Sign In
Sign Up Free
Navigation
🗺️
Live Classes
🗺️
Courses
🎬
Assignments
💡
Q & A
💡
My Profile
💡
Recruiter Board
Job Support
🎯
Interview Board
AI Tools
🌐
Project Explanation Agent
🛟
Support Works
Sign In
Sign Up Free →
Home
›
Python Basics in English
Class Variables
Python Basics in English
›
Class Variables
Class Variables
Python Basics in English
.
Now Watching
Previous
← Previous
Python Class Design
Lesson Progress
Next →
Class Realtime Example
Next
📄 View Reference Document & Notes
📋 Lesson Notes & Resources
4. Constructor –
__init__
The constructor is a special method named
__init__
which runs automatically when we create an object. It is used to
initialize instance variables
.
class
Student
:
def
__init__
(
self
,
name
,
course
):
self
.
name
=
name
self
.
course
=
course
# object creation
s1
=
Student
(
"Rahul"
,
"Python"
)
First parameter must be
self
(reference to current object).
We pass values at object creation – they come into the constructor parameters.
Inside constructor we store data into
self
attributes (instance variables).
5. Parameter Types in Class Methods
Class methods (including constructor) can use all normal Python parameter types.
Positional parameters
Values are passed in order.
Default parameters
We give a default value in the method definition.
Keyword parameters
We pass values using
name=value
style.
*args
Collects extra positional arguments as a tuple.
**kwargs
Collects extra keyword arguments as a dictionary.
class
Order
:
def
__init__
(
self
,
order_id
,
# positional
status
=
"NEW"
,
# default
*
items
,
# *args
**
extra_info
# **kwargs
):
self
.
order_id
=
order_id
self
.
status
=
status
self
.
items
=
items
self
.
extra_info
=
extra_info
6. Function Types inside a Class
Inside a class, functions are called
methods
. Common types:
Instance methods
Most common. First parameter is
self
. Can access and modify object data.
Class methods
(
@classmethod
)
First parameter is
cls
(class itself). Often used as alternative constructors.
Static methods
(
@staticmethod
)
No
self
or
cls
. A normal function kept inside class for grouping.
Special / dunder methods
(like
__str__
,
__len__
)
Used to customize behaviour of built-in functions and operators.
class
BankAccount
:
def
__init__
(
self
,
owner
,
balance
=
0
):
self
.
owner
=
owner
self
.
balance
=
balance
# Instance method
def
deposit
(
self
,
amount
):
self
.
balance
+=
amount
# Class method
@classmethod
def
from_string
(
cls
,
data
):
owner
,
bal_str
=
data
.
split
(
","
)
return
cls
(
owner
,
float
(
bal_str
))
# Static method
@staticmethod
def
is_valid_amount
(
amount
):
return
amount
>=
0
7. Quick Summary
Use
class
to define a blueprint.
Use
__init__
as constructor to initialize data.
Always keep
self
as first argument in instance methods.
Use different parameter types (
*args
,
**kwargs
) for flexible input.
Use instance / class / static methods based on what you need to access (object, class, or none).
8. Class Variable vs Instance Variable
Class Variable
→ Shared by all objects of the class. Defined inside the class but outside any method.
Stored in class memory, not in object memory.
Changing a class variable affects all objects.
Used for constant values or shared information.
Instance Variable
→ Unique to each object. Defined inside
__init__
using
self
.
Stored separately for each object.
Changing instance variable affects only that object.
Used to store object-specific data.
class
Employee
:
company
=
"TCS"
# class variable
def
__init__
(
self
,
name
,
salary
):
self
.
name
=
name
# instance variable
self
.
salary
=
salary
# instance variable
9. Instance Functions vs Class Functions
Instance Function
(Instance Method)
Most common method type.
First parameter is
self
.
Used to access instance variables.
Can also access class variables.
Class Function
(Class Method)
Defined using
@classmethod
.
First parameter is
cls
(the class itself).
Can access class variables but not instance variables.
Used for factory methods (alternative constructors).
class
Car
:
wheels
=
4
# class variable
def
__init__
(
self
,
brand
):
self
.
brand
=
brand
# instance variable
# Instance function
def
show_details
(
self
):
return
f"Brand: {self.brand}, Wheels: {Car.wheels}"
# Class function
@classmethod
def
change_wheels
(
cls
,
count
):
cls
.
wheels
=
count
Course Content
10 lessons
Python Basics in English
1
Basics Introduction
.
2
Python Data Types
.
3
Python Data Operators
.
4
Python Function Design
.
5
Python Class Design
.
▶
Class Variables
.
7
Class Realtime Example
.
8
Inheritance Class
.
9
Abstract Class
.
10
Overview of the OOPS concept
.
All Course Lessons
01
Python Basics in English
›
💬 Connect with us
✕
🎁 Refer & Earn
💬 WhatsApp
Earn for every successful referral
₹1000
per student who enrolls
How it works
1
Share your referral code with a friend who wants to learn Python or AWS
2
They enroll using your code and pay for the course
3
You receive ₹1000 credited to your account
Login
to see your referral code and start earning.
💬
Chat with us on WhatsApp
Have a question about the course, fees, or career guidance? We reply quickly.
Usually replies within a few hours · Mon–Sat 9AM–8PM IST
Chat on WhatsApp
No spam — business queries only.
💬
2
👑
Unlock Premium Access
Get full access to
all recorded classes, assignments, Q&A board and online tests
. Join 500+ students learning Python & AWS.
Maybe later
🚀 Get Premium Access