Answers for "declaring variable private in python"

2

Python private variables

# Make variables private by adding two underscored (_)
# in front of variable names.

# However, this is ***JUST A CONVENSION***.
# Private variables doesn't exist in Python. __var is still accesible.


# Example:
class User(object):
	def __init__(self, name, password):
		self.name = name				# Public variable
        self.__password = password		# Private variable
Posted by: Guest on November-08-2021

Code answers related to "declaring variable private in python"

Python Answers by Framework

Browse Popular Code Answers by Language