We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 777b0f3 commit e2a48b6Copy full SHA for e2a48b6
1 file changed
tests/basics/property.py
@@ -0,0 +1,54 @@
1
+class A:
2
+ def __init__(self, x):
3
+ self._x = x
4
+
5
+ @property
6
+ def x(self):
7
+ print("x get")
8
+ return self._x
9
10
+a = A(1)
11
+print(a.x)
12
13
+try:
14
+ a.x = 2
15
+except AttributeError:
16
+ print("AttributeError")
17
18
+class B:
19
20
21
22
+ def xget(self):
23
24
25
26
+ def xset(self, value):
27
+ print("x set")
28
+ self._x = value
29
30
+ x = property(xget, xset)
31
32
+b = B(3)
33
+print(b.x)
34
+b.x = 4
35
36
37
+class C:
38
39
40
41
42
43
44
45
46
+ @x.setter
47
+ def x(self, value):
48
49
50
51
+c = C(5)
52
+print(c.x)
53
+c.x = 6
54
0 commit comments