[Python] Why is my instance variable not updating inside a Python class?

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning OOP in Python. I created a class and tried to update an instance variable inside a method, but the value doesn’t change.

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

    def update_marks(self, value):
    marks = value # not updating self.marks ?

    s = Student("Shivam", 80)
    s.update_marks(95)
    print(s.marks) # still prints 80

    Continue reading...

Compartilhe esta Página