Skip to content

Itertools #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Italiano/1_introduction/1-DataScience.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
Expand All @@ -655,7 +655,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.5.6"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
Expand Down
69 changes: 40 additions & 29 deletions Italiano/1_introduction/4-OOP Programming.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"Un concetto simile all'incapsulamento è anche chiamato: occultamento dell'informazione, o meglio: Information Hiding. \n",
"L’information hiding, come l’incapsulamento fornisce lo stesso vantaggio: la flessibilità.\n",
"\n",
"### Astrazione\n",
"### Ereditarietà\n",
"L’ereditarietà costituisce il secondo principio fondamentale della programmazione ad oggetti. In generale, essa rappresenta un meccanismo che consente di creare nuovi oggetti che siano basati su altri già definiti. \n",
"\n",
"Si definisce oggetto figlio (child object) quello che eredita tutte o parte delle proprietà e dei metodi definiti nell’oggetto padre (parent object). \n",
Expand Down Expand Up @@ -510,13 +510,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['__class__',\n",
"['_Incapsulamento__x',\n",
" '__class__',\n",
" '__delattr__',\n",
" '__dict__',\n",
" '__dir__',\n",
Expand All @@ -541,23 +542,22 @@
" '__sizeof__',\n",
" '__str__',\n",
" '__subclasshook__',\n",
" '__weakref__',\n",
" '_incapsulamento__x']"
" '__weakref__']"
]
},
"execution_count": 12,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"class incapsulamento():\n",
"class Incapsulamento():\n",
" \n",
" def __init__(self):\n",
" self.__x = 0\n",
"\n",
"myclass = incapsulamento()\n",
"dir(myclass)\n"
"myclass = Incapsulamento()\n",
"dir(myclass)"
]
},
{
Expand All @@ -569,10 +569,8 @@
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from math import pi\n",
Expand All @@ -585,10 +583,12 @@
" self.blue = blue\n",
" \n",
"class FiguraGeometrica():\n",
" \n",
" def __init__(self, x, y, colore):\n",
" self.x = x\n",
" self.y = y\n",
" self.colore = colore\n",
" \n",
" def disegna(self):\n",
" raise \"Metodo Astratto!\"\n",
" \n",
Expand All @@ -609,11 +609,11 @@
" pass # Esegue il disegno della figura\n",
" \n",
" def getArea(self):\n",
" return int(pi * self.raggio)\n",
" return int(pi * self.raggio ** 2)\n",
" \n",
"class Rettangolo(FiguraGeometrica):\n",
" def __init__(self, x, y, base, altezza, colore):\n",
" Shape.__init__(self, x, y, colore)\n",
" FiguraGeometrica.__init__(self, x, y, colore)\n",
" self.base = base\n",
" self.altezza = altezza\n",
" \n",
Expand All @@ -626,15 +626,15 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.Cerchio object at 0x0000026FA21D67B8>\n",
"Area Cerchio: 94\n"
"<__main__.Cerchio object at 0x000002181F600F28>\n",
"Area Cerchio: 2827\n"
]
}
],
Expand All @@ -654,10 +654,8 @@
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"class Impiegato:\n",
Expand All @@ -676,6 +674,7 @@
" def visualizza(self):\n",
" Impiegato.visualizza(self)\n",
" print(f'Salario:{self.salario}')\n",
" \n",
"class Stagista(Impiegato):\n",
" '''Classe che rappresenta uno Stagista della azienda.'''\n",
" def __init__(self, nome, anni, tesi):\n",
Expand Down Expand Up @@ -718,12 +717,24 @@
"#### Esempio di Polimorfismo"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il polimorfismo permette al programma di fare uso di oggetti che espongono una stessa interfaccia, ma implementazioni diverse. \n",
"Infatti, l'interfaccia del tipo base definisce un contratto generale che sottoclassi diverse possono soddisfare in modi diversi - ma tutti conformi alla specifica comune stabilita dal tipo base. \n",
"\n",
"Di conseguenza, la parte del programma che fruisce di questa interfaccia - chiamata in gergo client - tratta in modo omogeneo tutti gli oggetti che forniscono un dato insieme di servizi, a prescindere dalle loro implementazioni interne (presumibilmente diverse tra loro) definite dalle rispettive classi. In virtù di questa possibilità, si può utilizzare lo stesso codice personalizzandone o modificandone anche radicalmente il comportamento, senza doverlo riscrivere, ma semplicemente fornendogli in input una differente implementazione del tipo base o dei tipi base.\n",
"Se usato bene, il polimorfismo permette di avere una struttura ad oggetti\n",
"\n",
"- estensibile, in quanto si può indurre il client ad invocare nuovi metodi personalizzati includendoli in una classe apposita;\n",
"- resistente, perché eventuali esigenze future nel programma o nella scrittura del codice potranno essere implementate fornendo ad un client già scritto una nuova classe scritta ad hoc."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"class Animale:\n",
Expand All @@ -741,7 +752,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -813,7 +824,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -827,7 +838,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.6"
"version": "3.7.1"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
Loading