What made the concept of self click for me, and this is completely ridiculous so you very well may get no miles out of this, but I treat building a class like building a Frankenstein monster. Attributes are physical features, methods are actions the monster can take, but "self" is what makes the monster alive, and thus self is the monster's (object's) "soul". That is, self is what made that particular monster (object) unique amongst other similar monsters (objects). I want to attack the village that is being mean about my sick experiments, and to really put a point on my powers, I also want to kidnap a villager. You know, evil scientist things. Since each monster has a soul, they can do independent things since the soul (self) makes them unique. Class Monster: def __init__(soul, name): soul.name = name def attack_village(): def kidnap_villager(): Now we "give life" to the monsters my instantiating (putting them on the table that lightning hits) two unique instances of the class: pat = Monster(pat) cris = Monster(cris) Despite being the "same" monster (same features, same look, same actions they can take), Pat and Cris can do things independently of the other. So I send Pat to kidnap a villager, and Cris to attack the village. pat.kidnap_villager() cris.attack_village() TL;DR: "self" is what makes each instance of a Class object unique. Answer from Deleted User on reddit.com
🌐
W3Schools
w3schools.com › python › python_class_self.asp
Python self Parameter
Note: The self parameter must be the first parameter of any method in the class. Without self, Python would not know which object's properties you want to access:
🌐
W3Schools
w3schools.com › python › gloss_python_self.asp
Python Self
Python Examples Python Compiler ... Training ... The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class....
Discussions

How does “self” in a class work?
What made the concept of self click for me, and this is completely ridiculous so you very well may get no miles out of this, but I treat building a class like building a Frankenstein monster. Attributes are physical features, methods are actions the monster can take, but "self" is what makes the monster alive, and thus self is the monster's (object's) "soul". That is, self is what made that particular monster (object) unique amongst other similar monsters (objects). I want to attack the village that is being mean about my sick experiments, and to really put a point on my powers, I also want to kidnap a villager. You know, evil scientist things. Since each monster has a soul, they can do independent things since the soul (self) makes them unique. Class Monster: def __init__(soul, name): soul.name = name def attack_village(): def kidnap_villager(): Now we "give life" to the monsters my instantiating (putting them on the table that lightning hits) two unique instances of the class: pat = Monster(pat) cris = Monster(cris) Despite being the "same" monster (same features, same look, same actions they can take), Pat and Cris can do things independently of the other. So I send Pat to kidnap a villager, and Cris to attack the village. pat.kidnap_villager() cris.attack_village() TL;DR: "self" is what makes each instance of a Class object unique. More on reddit.com
🌐 r/learnpython
70
262
December 22, 2021
Need Help in Self in python - Stack Overflow
Can someone please explain this code to as why it is written abc.name instead of mysillyobject.name? class Person: def __init__(mysillyobject, name, age): mysillyobject.name = name More on stackoverflow.com
🌐 stackoverflow.com
python - What is the purpose of the `self` parameter? Why is it needed? - Stack Overflow
Consider this example: class MyClass: def func(self, name): self.name = name I know that self refers to the specific instance of MyClass. But why must func explicitly include self as a More on stackoverflow.com
🌐 stackoverflow.com
I think I wasted my damn time on W3Schools.
If it helps you then it wasn't a waste of time. I'm a full time full stack dev and find that W3 often puts things into layman's terms that I may otherwise be having a hard time understanding More on reddit.com
🌐 r/learnprogramming
126
161
February 11, 2024
🌐
W3Schools
w3schools.com › python › python_challenges_class_self.asp
Python self Parameter Code Challenge
Python Examples Python Compiler ... Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Test your understanding of the self parameter by completing a small coding challenge. ... If you want to use W3Schools services as an educational ...
🌐
W3Schools
w3schools.com › python › exercise.asp
Exercise: - Python Self Parameter
Self Parameter3 q · Class Properties3 q · Class Methods5 q · Inheritance5 q · Polymorphism3 q · Encapsulation3 q · Inner Class3 q · File Handling3 q · Open File3 q · Write to File3 q · Remove File3 q by w3schools.com · Next Question » · Try Again · You have already completed these exercises! Do you want to take them again? Yes No · × · Close the exercise · You completed the Python Self Parameter Exercises from W3Schools.com ·
🌐
W3Schools
w3schools.com › python › python_inheritance.asp
Python Inheritance
class Student(Person): def __init__(self, fname, lname, year): super().__init__(fname, lname) self.graduationyear = year def welcome(self): print("Welcome", self.firstname, self.lastname, "to the class of", self.graduationyear) Try it Yourself » · If you add a method in the child class with the same name as a function in the parent class, the inheritance of the parent method will be overridden. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
Reddit
reddit.com › r/learnpython › how does “self” in a class work?
r/learnpython on Reddit: How does “self” in a class work?
December 22, 2021 -

You have to add “self” as an argument to a class method. Why this specific syntax and how does it get interpreted? Is this because it inherits from the Python object model?

Is there any language where public methods do not contain “self” as an argument?

Thank you

🌐
W3Schools
w3schools.com › python › gloss_python_object_methods.asp
Python Object Methods
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Objects can also contain methods. Methods in objects are functions that belong to the object. ... class Person: def __init__(self, name, age): self.name = name self.age = age def myfunc(self): print("Hello my name is " + self.name) p1 = Person("John", 36) p1.myfunc() Try it Yourself »
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › self-in-python-class
self in Python class - GeeksforGeeks
February 26, 2025 - Class attributes: Class attributes belong to the class itself they will be shared by all the instances. Such attributes are defined in the class body parts usually at the top, for legibility. Python # Write Python code here class sampleclass: count = 0 # class attribute def increase(self): samplecla
🌐
Stack Overflow
stackoverflow.com › questions › 63412753 › need-help-in-self-in-python
Need Help in Self in python - Stack Overflow
https://www.w3schools.com/python/gloss_python_self.asp · python · python-3.x · Share · Improve this question · Follow · edited Aug 14, 2020 at 12:29 · Klaus D. 14.5k55 gold badges4444 silver badges5353 bronze badges · asked Aug 14, 2020 at 12:27 · Shivam PatelShivam Patel ·
🌐
W3Schools
w3schools.com › PYTHON › python_class_methods.asp
Python Class Methods
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Methods are functions that belong to a class. They define the behavior of objects created from the class. ... class Person: def __init__(self, name): self.name = name def greet(self): print("Hello, my name is " + self.name) p1 = Person("Emil") p1.greet() Try it Yourself »
🌐
W3Schools
w3schools.invisionzone.com › suggestions
Phython Tutorial - Suggestions - W3Schools Forum
June 25, 2019 - There's no enough explanation to the variables used in the tutorials. For example, what is "self"? Is it an object or just a parameter? class Person: def __init__(self, name, age): self.name = name self.age = agep1 = Person("John", 36)print(p1.name)print(p1.age)
🌐
Quora
quora.com › What-is-Python-self
What is Python self? - Quora
Answer (1 of 2): It is a variable name, and nothing more. But it is the traditional variable name for the first parameter of a method. When you make a call of the form [code ]obj.method(parameters...)[/code] in Python, what you really mean (most of the time) is [code ]obj.__class__.method(obj...
🌐
W3Schools
w3schools.com › PYTHON › python_class_init.asp
Python __init__() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... All classes have a built-in method called __init__(), which is always executed when the class is being initiated. The __init__() method is used to assign values to object properties, or to perform operations that are necessary when the object is being created. Create a class named Person, use the __init__() method to assign values for name and age: class Person: def __init__(self, name, age): self.name = name self.age = age p1 = Person("Emil", 36) print(p1.name) print(p1.age) Try it Yourself »
🌐
W3Schools
w3schools.in › python › classes-objects
Python Object Oriented - W3Schools
class karl(object) : def __init__(self, x, y): self.x = x self.y = y def sample(self) : print ("This is just a sample code")
🌐
Programiz
programiz.com › article › python-self-why
self in Python, Demystified
This is the reason the first parameter of a function in class must be the object itself. Writing this parameter as self is merely a convention. It is not a keyword and has no special meaning in Python. We could use other names (like this) but it is highly discouraged.
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.4 documentation
It is not necessary that the function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok. For example: # Function defined outside the class def f1(self, x, y): return min(x, x+y) class C: f = f1 def g(self): return 'hello world' h = g
🌐
W3Schools
w3schools.com › python › gloss_python_class_init.asp
Python __init__() Function
Note: The __init__() method is called automatically every time the class is being used to create a new object. Python Syntax Tutorial Class Create Class Object Methods self Modify Object Properties Delete Object Properties Delete Object Class pass Statement ... If you want to use W3Schools services ...
🌐
Edureka
edureka.co › blog › self-in-python
Self in Python Class | What is the Use of Python Self?
December 5, 2024 - With this keyword, you can access the attributes and methods of the class in python. It binds the attributes with the given arguments. The reason why we use self is that Python does not use the ‘@’ syntax to refer to instance attributes.
🌐
W3Schools
w3schools.com › python
Python Tutorial
Many chapters in this tutorial end with an exercise where you can check your level of knowledge. ... Learn by examples! This tutorial supplements all explanations with clarifying examples. ... Test your Python skills with a quiz. ... This is an optional feature. You can study at W3Schools without creating an account.