Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca97716

Browse files
committed
Property
1 parent 2aa3f94 commit ca97716

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ class C(A, B): pass
10121012
```
10131013

10141014
### Property
1015+
**Pythonic way to implement getters and setters.**
10151016
```python
10161017
class MyClass:
10171018
@property

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@
971971
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()
972972
[&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]
973973
</span></code></pre>
974-
<div><h3 id="property">Property</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span>:</span>
974+
<div><h3 id="property">Property</h3><p><strong>Pythonic way to implement getters and setters.</strong></p><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span>:</span>
975975
<span class="hljs-meta"> @property</span>
976976
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">a</span><span class="hljs-params">(self)</span>:</span>
977977
<span class="hljs-keyword">return</span> self._a
@@ -981,6 +981,7 @@
981981
self._a = value
982982
</code></pre></div>
983983

984+
984985
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>el = MyClass()
985986
<span class="hljs-meta">&gt;&gt;&gt; </span>el.a = <span class="hljs-number">123</span>
986987
<span class="hljs-meta">&gt;&gt;&gt; </span>el.a

0 commit comments

Comments
 (0)