About self while learning Python class

Asked 2 years ago, Updated 2 years ago, 11 views

class file:
    def __init__(self, mp3, mp4, txt):
        self.mp3 = mp3
        self.mp4 = mp4
        self.txt = txt

I don't know why I have to do this. What happens if self.txt = txt doesn't process this? I don't understand the use of self yet, so I have a hard time moving forward.

python

2022-09-20 17:59

1 Answers

In the method, self means the object. If self is omitted from the member variable declaration/assignment, the variable is It is created in the scope of the called method, not in the namespace of the instance being created.


2022-09-20 17:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.