Python doesn't have the concept of private methods or attributes. It's all about how you implement your class. But you can use pseudo-private variables (name mangling); any variable preceded by __(two underscores) becomes a pseudo-private variable.

From the documentation:

Since there is a valid use-case for class-private members (namely to avoid name clashes of names with names defined by subclasses), there is limited support for such a mechanism, called name mangling. Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class.

class A:
    def __private(self):
       pass

So __private now actually becomes _A__private.

Example of a static method:

>>> class A:
...     @staticmethod         # Not required in Python 3.x
...     def __private():
...         print 'hello'
...
>>> A._A__private()
hello
Answer from Ashwini Chaudhary on Stack Overflow
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-private-methods-explained
Python Private Methods Explained | DataCamp
March 27, 2024 - Think of encapsulation as a process ... what is needed (abstraction). Private methods are key to achieving this encapsulation by hiding the internal implementation details of a class....
๐ŸŒ
Linux Manual Page
linux.die.net โ€บ diveintopython โ€บ html โ€บ object_oriented_framework โ€บ private_functions.html
5.9. Private Functions - Python
If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, it's private; everything else is public. Python has no concept of protected class methods (accessible only in their own class and descendant classes).
Discussions

oop - Private methods in Python - Stack Overflow
I would like to have a function in my class, which I am going to use only inside methods of this class. I will not call it outside the implementations of these methods. In C++, I would use a method More on stackoverflow.com
๐ŸŒ stackoverflow.com
Do you use private methods/attributes
I can see why he doesn't care about them and it's not something I'm particularly quick to call out in code review. That said, I think they still have their uses. It's helpful to have an easy way to mark functions as some internal logic to your module/class or as a public function. I think it's good for someone using my code to know it's been designed for them to use foo and they shouldn't need to directly call _bar. They can then do whatever they want with that knowledge, I'm not their mother. More on reddit.com
๐ŸŒ r/learnpython
26
20
July 12, 2024
encapsulation - Why are Python's 'private' methods not actually private? - Stack Overflow
Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like this: __myPrivateMethod(). How, then, can one explain this &g... More on stackoverflow.com
๐ŸŒ stackoverflow.com
class - When to use private methods in Python - Software Engineering Stack Exchange
I have a class, but every method in it should be private (apart form __init__ and __str__). Should I denote every method with a double underscore, or is that deemed bad practice? More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
September 30, 2013
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ private-methods-in-python
Private Methods in Python - GeeksforGeeks
July 12, 2025 - Private methods are those methods that should neither be accessed outside the class nor by any base class. In Python, there is no existence of Private methods that cannot be accessed except inside a class.
Top answer
1 of 5
69

Python doesn't have the concept of private methods or attributes. It's all about how you implement your class. But you can use pseudo-private variables (name mangling); any variable preceded by __(two underscores) becomes a pseudo-private variable.

From the documentation:

Since there is a valid use-case for class-private members (namely to avoid name clashes of names with names defined by subclasses), there is limited support for such a mechanism, called name mangling. Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class.

class A:
    def __private(self):
       pass

So __private now actually becomes _A__private.

Example of a static method:

>>> class A:
...     @staticmethod         # Not required in Python 3.x
...     def __private():
...         print 'hello'
...
>>> A._A__private()
hello
2 of 5
10

Python doesn't have the concept of 'private' the way many other languages do. It is built on the consenting adult principle that says that users of your code will use it responsibly. By convention, attributes starting with a single or double leading underscore will be treated as part of the internal implementation, but they are not actually hidden from users. Double underscore will cause name mangling of the attribute name though.

Also, note that self is only special by convention, not by any feature of the language. Instance methods, when called as members of an instance, are implicitly passed the instance as a first argument, but in the implementation of the method itself, that argument can technically be named any arbitrary thing you want. self is just the convention for ease of understanding code. As a result, not including self in the signature of a method has no actual functional effect other than causing the implicit instance argument to be assigned to the next variable name in the signature.

This is of course different for class methods, which receive the instance of the class object itself as an implicit first argument, and static methods, which receive no implicit arguments at all.

๐ŸŒ
Medium
purnimachowrasia.medium.com โ€บ what-is-private-method-in-python-778bd6e77bad
What is Private method in Python? | by Purnima Chowrasia | Medium
March 26, 2025 - As this __init__() method is prefixed with double underscore and this method is intended to be used internally by the class and not by outside user. Hence, swearing by the python convention for private methods, yes __init__() is private method.
๐ŸŒ
Afternerd
afternerd.com โ€บ blog โ€บ python-private-methods
Private Methods in Python - Afternerd
February 11, 2021 - Check out my in-depth Python OOP course. A private method is a Class method that can only be called from inside the Class where it is defined.
๐ŸŒ
Thibaultbl
thibaultbl.github.io โ€บ 2018-07-08-private-class-in-python
Python Private method and functions
A private class method is a method that can be called only inside his class. The concept of protected method doesn't exist in Python (accessible within his class and all classes that inherit his classes).
Find elsewhere
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ python-private-methods
Private Methods in Python | FavTutor
October 18, 2021 - When we try to access this method ... access the private attribute and methods, right? In python, private access to private methods and attributes is not enforced....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ do you use private methods/attributes
r/learnpython on Reddit: Do you use private methods/attributes
July 12, 2024 -

Hi,

Some time ago I work with a senior that don't use private method because he said you could access them anyway, so it didn't make sense, in other languages it did, because it was impossible to access it and that's why it was useful, but not in Python.

What do you think, have sense?

(I want to create a survey but I can't, so I'll put two comments, and wait for your upvotes)

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ private-methods-in-python
Python - Private Variables
October 17, 2024 - Similar to private variables, we can also define private methods in Python. Private methods are methods that are only accessible within the class they are defined in. They are not accessible from outside the class or from any subclass.
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ python โ€บ public-private-protected-modifiers
public, protected, private members in Python
class Student: __schoolName = 'XYZ School' # private class attribute def __init__(self, name, age): self.__name=name # private instance attribute self.__salary=age # private instance attribute def __display(self): # private method print('This is private method.') std = Student("Bill", 25) print(std.__schoolName) #AttributeError print(std.__name) #AttributeError print(std.__display()) #AttributeError ... Python performs name mangling of private variables.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ python private method
Python Private Method | Rules and regulations of Python private method
April 4, 2023 - However, as per the convention, a method or name prefixed with one underscore is treated as non-public. Hence, private members can be accessed outside the class by making it nonpublic like _classname__privatevariable. This is called โ€œname manglingโ€. In a nutshell, we can say Python not truly supports the fundamentals of private.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Bogotobogo
bogotobogo.com โ€บ python โ€บ python_private_attributes_methods.php
Python Tutorial: Private attributes and methods - 2020
How can we use the private method. If we try: >>> from p2 import P >>> x = P('Alex', 'amem') >>> x.__foo() Traceback (most recent call last): File " ... Python Home Introduction Running Python Programs (os, sys, import) Modules and IDLE (Import, Reload, exec) Object Types - Numbers, Strings, ...
๐ŸŒ
Medium
medium.com โ€บ @techclaw โ€บ python-private-method-enhancing-encapsulation-and-security-ebbbcb5766b9
Python Private Method: Enhancing Encapsulation and Security | by TechClaw | Medium
August 8, 2023 - It refers to the bundling of data and methods that operate on that data within a single unit, i.e., the class. By using private methods, we can hide the internal workings of an object from the outside world, making it more robust and less prone ...
๐ŸŒ
Python Basics
python-basics-tutorial.readthedocs.io โ€บ en โ€บ 24.3.0 โ€บ oop โ€บ private.html
Private variables and methods - Python Basics 24.3.0
A private variable or private method is a variable that is not visible outside the methods of the class in which it is defined. Private variables and methods are useful for two reasons: they increa...