private variables in python
Can anyone pls explain what are single undescore and double underscore variables and how they can be accessed outside of any class?
You can access them just by writing them with the underscores: print(yourInstance._thatValue) Python has no privacy. It relies on the convention that programmers *voluntarily* don't touch members that start with _.
Single Underscore: > In Interpreter >> After a name >> Before a name ** *** Double Underscore: __leading_double_underscore __before_after__
if we want to calculate how much money we will have on the 5th day, we can use this expression: 0.01*(2**5) = 0.32 dollars (multiply the penny by 2 raised to the power of 5).
For everyone saying <variable> = None is declaration without initialization, you are wrong. The assignment operator = is there, meaning something is being assigned to the variable, which defines the variable type and initializes it, even if the thing to be assigned was of a None type.
Variable with leading "_" single underscore is just a convention to tell that this variable shall not be imported. You can say it's a soft rule(Rules are meant to be broken XD) Variable with leading '__' double underscore is to tell the interpreter that this variable is not shared and is local to only single class. It's also called name mangling.
To declare private variable as __var And to access this variable as instance name._classname__var
If you use a variable with a singel underscore than it is called weakly private, but if you use a variable with doublekunderscore than it is called strongly pirvate
I do not understand the question!
Single underscore is private
Privacy doesn't exist in python but you can use conventions like Double underscore for private, if you use a single underscore it means current class
I can not
Yes, is possible.
a single underscore at starting is less private and a double underscore at starting is more private
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
Python palindrome challenge.
Number of Ones ( C++ ) question!