attribute priv c3 a9 python

Solutions on MaxInterview for attribute priv c3 a9 python by the best coders in the world

showing results for - "attribute priv c3 a9 python"
Lukas
21 Feb 2020
1class point:
2    def __init__(self,a,b):
3        self._x=a 
4        self.y= b
5
6p=point(1,2)
7print(p.y)
8#l'attribut y de l'objet p est par defaut publique 
9print(p.x)
10#l'attribut x est privé(_x) donc on ne peut acceder directement a sa valeur au dehors de la classe
11
12#output --------------------------------------->
13
142
15
16
17Traceback (most recent call last):
18  File "file0.py", line 9, in <module>
19    print(p.x)
20AttributeError: 'point' object has no attribute 'x'
21