How Python implements “Data Encapsulation”?
Data privacy or “data encapsulation” is provided by Python by default. In Python every variable or method is scoped within its parent code block. Look at the below function-
- def newcurrencynote():
- newnote = 2000
- print("This is new" + newnote + "currency note")
In the above function newcurrencynote() the variable newnote inside the function has “ local” scope within that function, in other words it is private to that functions only and is not accessible outside that function . So, the first print function gives an error stating that you should initialize the variable first and then print it, but since the second function is trying to access the function itself so it will print the value of the variable.
If you found this post helpful and you have any suggestion to improve my blog then do post your comments below. Additionally you can also bug me on Quora. You can also find me on Twitter or Facebook. So, why wait go ahead and start exploring.
If you wanna get started in learning Python then why not get started with the python basics chapter. Check out this link to access the Python Basic Chapter for free.
If you want to download a copy of the chapter then purchase the chapter by clicking on the following link.