A
A
Alexander Bureyko2021-11-14 12:46:22
Python
Alexander Bureyko, 2021-11-14 12:46:22

Why doesn't an error occur?

Hello, I'm learning python OOP. I don't understand how we can access the self.x variable in the 5th line of the code? because self.x was declared in the local scope

class Point():
    def __init__(self, x):
        self.x = x
    def func(self):
        print(self.x)
p = Point(5)
p.func()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question