Home › Tutorials › Python OOP Concepts › Instance Variables
Instance Variables

Instance Variables


4. Instance Variables

Instance variables belong to each object separately. Their values can differ from one object to another.

Syntax

class Test:
    def __init__(self, x):
        self.x = x

Example

class Student:
    def __init__(self, name):
        self.name = name

s1 = Student("Ravi")
s2 = Student("Kiran")
print(s1.name)
print(s2.name)

Output

Ravi
Kiran
Example

🏋️ Test Yourself With Exercises

Take our quiz on Instance Variables to test your knowledge.

Browse Quizzes »