|
|
@ -15,9 +15,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_external/reveal.min.css"> |
|
|
|
<link rel="stylesheet" href="_external/reveal.min.css"> |
|
|
|
<link rel="stylesheet" href="_external/default.css" id="theme"> |
|
|
|
<link rel="stylesheet" href="_external/default.css" id="theme"> |
|
|
|
|
|
|
|
<link rel='stylesheet' href='_external/hightlight-default.min.css'> |
|
|
|
|
|
|
|
|
|
|
|
<!-- For syntax highlighting --> |
|
|
|
<!-- For syntax highlighting --> |
|
|
|
<link rel="stylesheet" href="_external/zenburn.css"> |
|
|
|
<!-- <link rel="stylesheet" href="_external/zenburn.css"> --> |
|
|
|
|
|
|
|
<link rel='stylesheet' href='_external/obsidian.css'> |
|
|
|
|
|
|
|
|
|
|
|
<!-- If the query includes 'print-pdf', include the PDF print sheet --> |
|
|
|
<!-- If the query includes 'print-pdf', include the PDF print sheet --> |
|
|
|
<script> |
|
|
|
<script> |
|
|
@ -590,6 +592,17 @@ Julio |
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<p>No Python 3, basta usar <code>super().__init__()</code>. |
|
|
|
<p>No Python 3, basta usar <code>super().__init__()</code>. |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
|
|
|
|
<p>Propriedades podem ser injetadas a qualquer momento.</p> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> class A(object): |
|
|
|
|
|
|
|
>>> def __init__(self): |
|
|
|
|
|
|
|
>>> self.value = 10 |
|
|
|
|
|
|
|
>>> |
|
|
|
|
|
|
|
>>> a = A() |
|
|
|
|
|
|
|
>>> a.name = 'Julio' |
|
|
|
|
|
|
|
</section> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
@ -690,9 +703,9 @@ Julio |
|
|
|
>>> print kwargs |
|
|
|
>>> print kwargs |
|
|
|
>>> |
|
|
|
>>> |
|
|
|
>>> a(a=1) |
|
|
|
>>> a(a=1) |
|
|
|
{a: 1} |
|
|
|
{'a': 1} |
|
|
|
>>> a(value1=10, a=2) |
|
|
|
>>> a(value1=10, a=2) |
|
|
|
{value1: 10, a: 2} |
|
|
|
{'value1': 10, 'a': 2} |
|
|
|
</code></pre></p> |
|
|
|
</code></pre></p> |
|
|
|
|
|
|
|
|
|
|
|
<p><code>**</code> pega somente os parâmetros que tem nome.</p> |
|
|
|
<p><code>**</code> pega somente os parâmetros que tem nome.</p> |
|
|
@ -706,10 +719,10 @@ Julio |
|
|
|
>>> |
|
|
|
>>> |
|
|
|
>>> a(a=1) |
|
|
|
>>> a(a=1) |
|
|
|
[] |
|
|
|
[] |
|
|
|
{a: 1} |
|
|
|
{'a': 1} |
|
|
|
>>> a(1, 2, 3, a=5) |
|
|
|
>>> a(1, 2, 3, a=5) |
|
|
|
[1, 2, 3] |
|
|
|
[1, 2, 3] |
|
|
|
{a: 5} |
|
|
|
{'a': 5} |
|
|
|
</code></pre></p> |
|
|
|
</code></pre></p> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
@ -722,6 +735,8 @@ Julio |
|
|
|
>>> print 'name = ', name |
|
|
|
>>> print 'name = ', name |
|
|
|
>>> print 'kwargs =', kwargs |
|
|
|
>>> print 'kwargs =', kwargs |
|
|
|
</code></pre></p> |
|
|
|
</code></pre></p> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p>Saída de uma chamada desta função fica a cargo do leitor.</p> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
@ -742,7 +757,7 @@ Julio |
|
|
|
>>> def funcao(a, b, c): |
|
|
|
>>> def funcao(a, b, c): |
|
|
|
>>> return (a + b) / c |
|
|
|
>>> return (a + b) / c |
|
|
|
>>> |
|
|
|
>>> |
|
|
|
>>> params = {b: 2, c: 3, a:10} |
|
|
|
>>> params = {'b': 2, 'c': 3, 'a':10} |
|
|
|
>>> funcao(**params) |
|
|
|
>>> funcao(**params) |
|
|
|
</code></pre></p> |
|
|
|
</code></pre></p> |
|
|
|
</section> |
|
|
|
</section> |
|
|
@ -768,6 +783,25 @@ Julio |
|
|
|
>>> |
|
|
|
>>> |
|
|
|
</code></pre></p> |
|
|
|
</code></pre></p> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
|
|
|
|
<p>Como funções são cidadãos de primeira classe e classes podem |
|
|
|
|
|
|
|
ter funções injetadas, pode-se extender uma classe em tempo |
|
|
|
|
|
|
|
de execução.</p> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p><pre><code data-trim> |
|
|
|
|
|
|
|
>>> class A(object): |
|
|
|
|
|
|
|
>>> def __init__(self): |
|
|
|
|
|
|
|
>>> self.value = 10 |
|
|
|
|
|
|
|
>>> |
|
|
|
|
|
|
|
>>> def show_name(self): |
|
|
|
|
|
|
|
>>> print 'Julio' |
|
|
|
|
|
|
|
>>> |
|
|
|
|
|
|
|
>>> a = A() |
|
|
|
|
|
|
|
>>> a.show = show_name |
|
|
|
|
|
|
|
>>> a.show() |
|
|
|
|
|
|
|
</code></pre></p> |
|
|
|
|
|
|
|
</section> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
@ -865,7 +899,7 @@ Julio |
|
|
|
{ src: '_external/classList.js', condition: function() { return !document.body.classList; } }, |
|
|
|
{ src: '_external/classList.js', condition: function() { return !document.body.classList; } }, |
|
|
|
{ src: '_external/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
|
{ src: '_external/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
|
{ src: '_external/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
|
{ src: '_external/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
|
{ src: '_external/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, |
|
|
|
{ src: '_external/highlight.min.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, |
|
|
|
{ src: '_external/zoom.js', async: true, condition: function() { return !!document.body.classList; } }, |
|
|
|
{ src: '_external/zoom.js', async: true, condition: function() { return !!document.body.classList; } }, |
|
|
|
{ src: '_external/notes.js', async: true, condition: function() { return !!document.body.classList; } } |
|
|
|
{ src: '_external/notes.js', async: true, condition: function() { return !!document.body.classList; } } |
|
|
|
] |
|
|
|
] |
|
|
|