Wednesday 9 March 2022

what are python private variables its best practices?

Python, private variables are variables that are meant to be used only within the class in which they are defined. Private variables are defined by prefixing the variable name with two underscores (__) at the beginning of the variable name.

For example, if you have a class called Person and you want to define a private variable called __age, you would write:

class Person: def __init__(self, name, age): self.name = name self.__age = age


Read more »

Labels: , ,