From dbcc177a99f94329c828bd30166da8cb04116850 Mon Sep 17 00:00:00 2001 From: Rahul Thakur Date: Tue, 16 Oct 2018 01:36:05 +0530 Subject: [PATCH] Included Private variables in Class article of Python (#18803) * Included Private variables in Class * Removed Typos --- .../pages/guide/english/python/class/index.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/client/src/pages/guide/english/python/class/index.md b/client/src/pages/guide/english/python/class/index.md index 852cc1baec..52104ac293 100644 --- a/client/src/pages/guide/english/python/class/index.md +++ b/client/src/pages/guide/english/python/class/index.md @@ -79,4 +79,24 @@ class Complex: x = Complex(3.0, -4.5) >>> x.r, x.i (3.0, -4.5) -``` \ No newline at end of file +``` + +#### Private Variables in Class: + +Every programming language which follows OOPs (Object Oriented Programming) concept has some mechanism of data hiding.In python if some variable needs to be hidden from the outside world we use the concept of private variables by using `__` before he variable name. + +for example: +``` +class Foo: + def __init__(self): + self.__privatenum = 3011 + + +Now if we try to access __privatenum outside the class we will get error: +x = Foo() +x.__privatenum # gives following error : 'Foo' object has no attribute '__privatenum' + +``` + + +