Browse Source

Class

pull/121/head
Jure Šorn 2 years ago
parent
commit
48a4bb5b40
2 changed files with 6 additions and 6 deletions
  1. 6
      README.md
  2. 6
      index.html

6
README.md

@ -1017,7 +1017,7 @@ class C(A, B): pass
class Person:
@property
def name(self):
return ' '.join(a if a == 'van' else a.title() for a in self._name)
return ' '.join(a.title() for a in self._name)
@name.setter
def name(self, value):
@ -1026,9 +1026,9 @@ class Person:
```python
>>> person = Person()
>>> person.name = ' gUiDo VaN rOsSuM '
>>> person.name = ' jEaN-lUc gOdArD '
>>> person.name
'Guido van Rossum'
'Jean-Luc Godard'
```
### Dataclass

6
index.html

@ -861,7 +861,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<div><h3 id="property">Property</h3><p><strong>Pythonic way of implementing 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">Person</span>:</span>
<span class="hljs-meta"> @property</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">name</span><span class="hljs-params">(self)</span>:</span>
<span class="hljs-keyword">return</span> <span class="hljs-string">' '</span>.join(a <span class="hljs-keyword">if</span> a == <span class="hljs-string">'van'</span> <span class="hljs-keyword">else</span> a.title() <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> self._name)
<span class="hljs-keyword">return</span> <span class="hljs-string">' '</span>.join(a.title() <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> self._name)
<span class="hljs-meta"> @name.setter</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">name</span><span class="hljs-params">(self, value)</span>:</span>
@ -870,9 +870,9 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>person = Person()
<span class="hljs-meta">&gt;&gt;&gt; </span>person.name = <span class="hljs-string">' gUiDo VaN rOsSuM '</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>person.name = <span class="hljs-string">' jEaN-lUc gOdArD '</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>person.name
<span class="hljs-string">'Guido van Rossum'</span>
<span class="hljs-string">'Jean-Luc Godard'</span>
</code></pre>
<div><h3 id="dataclass">Dataclass</h3><p><strong>Decorator that automatically generates init(), repr() and eq() special methods.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass, field

Loading…
Cancel
Save