updated example codeblocks (#22292)

Last Codeblock wasn't set to Python.
Wrapped the Ellipses in Comments to get valid Python inside Codeblocks.
pull/22294/head^2
noelli 2018-11-19 14:23:20 +01:00 committed by Tom
parent 0216725df6
commit 368cabee95
1 changed files with 6 additions and 8 deletions

View File

@ -24,9 +24,9 @@ The simplest form of class definition looks like this:
```python
class ClassName:
<statement-1>
...
...
...
# ...
# ...
# ...
<statement-N>
```
@ -74,7 +74,7 @@ class Complex:
def __init__(self, realpart, imagpart):
self.r = realpart
self.i = imagpart
...
# ...
x = Complex(3.0, -4.5)
>>> x.r, x.i
@ -86,16 +86,14 @@ x = Complex(3.0, -4.5)
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:
```
```python
class Foo:
def __init__(self):
self.__privatenum = 3011
Now if we try to access __privatenum outside the class we will get error:
# 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'
```
## Simple class and Object Implementation