Commit 834b7496 authored by geobumac's avatar geobumac
parents 5d319062 91ad99ba
...@@ -601,9 +601,9 @@ ...@@ -601,9 +601,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"array([[2., 2., 9., 4.],\n", "array([[2., 9., 8., 6.],\n",
" [6., 6., 3., 6.],\n", " [8., 4., 2., 9.],\n",
" [7., 9., 9., 8.]])" " [1., 1., 4., 5.]])"
] ]
}, },
"execution_count": 26, "execution_count": 26,
...@@ -644,12 +644,12 @@ ...@@ -644,12 +644,12 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"array([[2., 2.],\n", "array([[2., 9.],\n",
" [9., 4.],\n", " [8., 6.],\n",
" [6., 6.],\n", " [8., 4.],\n",
" [3., 6.],\n", " [2., 9.],\n",
" [7., 9.],\n", " [1., 1.],\n",
" [9., 8.]])" " [4., 5.]])"
] ]
}, },
"execution_count": 28, "execution_count": 28,
...@@ -669,10 +669,10 @@ ...@@ -669,10 +669,10 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"array([[2., 6., 7.],\n", "array([[2., 8., 1.],\n",
" [2., 6., 9.],\n", " [9., 4., 1.],\n",
" [9., 3., 9.],\n", " [8., 2., 4.],\n",
" [4., 6., 8.]])" " [6., 9., 5.]])"
] ]
}, },
"execution_count": 29, "execution_count": 29,
...@@ -735,9 +735,9 @@ ...@@ -735,9 +735,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"array([[2., 2., 9., 4.],\n", "array([[2., 9., 8., 6.],\n",
" [6., 6., 3., 6.],\n", " [8., 4., 2., 9.],\n",
" [7., 9., 9., 8.]])" " [1., 1., 4., 5.]])"
] ]
}, },
"execution_count": 32, "execution_count": 32,
...@@ -856,11 +856,11 @@ ...@@ -856,11 +856,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"a -0.192610\n", "a 1.085164\n",
"b 0.957230\n", "b 0.684054\n",
"c -0.917233\n", "c -3.137046\n",
"d 1.156523\n", "d -0.780916\n",
"e -0.539532\n", "e 0.497413\n",
"dtype: float64" "dtype: float64"
] ]
}, },
...@@ -882,11 +882,11 @@ ...@@ -882,11 +882,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"0 -0.856313\n", "0 -0.165303\n",
"1 -0.342923\n", "1 0.089697\n",
"2 -1.398583\n", "2 -1.680879\n",
"3 0.170869\n", "3 -0.160729\n",
"4 1.049196\n", "4 0.235082\n",
"dtype: float64" "dtype: float64"
] ]
}, },
...@@ -963,7 +963,7 @@ ...@@ -963,7 +963,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"-0.19261011238315226" "1.0851635954341003"
] ]
}, },
"execution_count": 40, "execution_count": 40,
...@@ -983,9 +983,9 @@ ...@@ -983,9 +983,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"a -0.192610\n", "a 1.085164\n",
"b 0.957230\n", "b 0.684054\n",
"c -0.917233\n", "c -3.137046\n",
"dtype: float64" "dtype: float64"
] ]
}, },
...@@ -1006,8 +1006,9 @@ ...@@ -1006,8 +1006,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"b 0.957230\n", "a 1.085164\n",
"d 1.156523\n", "b 0.684054\n",
"e 0.497413\n",
"dtype: float64" "dtype: float64"
] ]
}, },
...@@ -1028,11 +1029,11 @@ ...@@ -1028,11 +1029,11 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"a -0.385220\n", "a 2.170327\n",
"b 1.914460\n", "b 1.368108\n",
"c -1.834466\n", "c -6.274092\n",
"d 2.313046\n", "d -1.561832\n",
"e -1.079065\n", "e 0.994826\n",
"dtype: float64" "dtype: float64"
] ]
}, },
...@@ -1053,10 +1054,10 @@ ...@@ -1053,10 +1054,10 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"a False\n", "a True\n",
"b True\n", "b True\n",
"c False\n", "c False\n",
"d True\n", "d False\n",
"e False\n", "e False\n",
"dtype: bool" "dtype: bool"
] ]
...@@ -1078,7 +1079,7 @@ ...@@ -1078,7 +1079,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"-0.19261011238315226" "1.0851635954341003"
] ]
}, },
"execution_count": 45, "execution_count": 45,
...@@ -1212,7 +1213,7 @@ ...@@ -1212,7 +1213,7 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 5.3.2 DataFrame\n", "### 5.3.2 DataFrame\n",
"DataFrame es un estructura bidimensiona etiquetada con columnas que pueden ser de diferentes tipos, es el objeto mas usado en pandas, se puede pensar en ella como un diccionario de **Series**. **DataFrame** acepta diferentes tipos de entradas como:\n", "DataFrame es un estructura bidimensional etiquetada con columnas que pueden ser de diferentes tipos, es el objeto mas usado en pandas, se puede pensar en ella como un diccionario de **Series**. **DataFrame** acepta diferentes tipos de entradas como:\n",
"* Diccionarios de arreglos unidimensionales, listas dicionarios o series. \n", "* Diccionarios de arreglos unidimensionales, listas dicionarios o series. \n",
"* 2-D numpy.ndarray\n", "* 2-D numpy.ndarray\n",
"* Series\n", "* Series\n",
...@@ -1236,7 +1237,7 @@ ...@@ -1236,7 +1237,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),\n", "d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),\n",
" 'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}" " 'two': pd.Series([1., 2., 3., 4.], index=['a', 'x', 'c', 'd'])}"
] ]
}, },
{ {
...@@ -1287,7 +1288,7 @@ ...@@ -1287,7 +1288,7 @@
" <tr>\n", " <tr>\n",
" <th>b</th>\n", " <th>b</th>\n",
" <td>2.0</td>\n", " <td>2.0</td>\n",
" <td>2.0</td>\n", " <td>NaN</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>c</th>\n", " <th>c</th>\n",
...@@ -1299,6 +1300,11 @@ ...@@ -1299,6 +1300,11 @@
" <td>NaN</td>\n", " <td>NaN</td>\n",
" <td>4.0</td>\n", " <td>4.0</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n",
" <th>x</th>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
...@@ -1306,9 +1312,10 @@ ...@@ -1306,9 +1312,10 @@
"text/plain": [ "text/plain": [
" one two\n", " one two\n",
"a 1.0 1.0\n", "a 1.0 1.0\n",
"b 2.0 2.0\n", "b 2.0 NaN\n",
"c 3.0 3.0\n", "c 3.0 3.0\n",
"d NaN 4.0" "d NaN 4.0\n",
"x NaN 2.0"
] ]
}, },
"execution_count": 54, "execution_count": 54,
...@@ -1339,6 +1346,7 @@ ...@@ -1339,6 +1346,7 @@
"b 2.0\n", "b 2.0\n",
"c 3.0\n", "c 3.0\n",
"d NaN\n", "d NaN\n",
"x NaN\n",
"Name: one, dtype: float64" "Name: one, dtype: float64"
] ]
}, },
...@@ -1394,8 +1402,8 @@ ...@@ -1394,8 +1402,8 @@
" <tr>\n", " <tr>\n",
" <th>b</th>\n", " <th>b</th>\n",
" <td>2.0</td>\n", " <td>2.0</td>\n",
" <td>2.0</td>\n", " <td>NaN</td>\n",
" <td>4.0</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
...@@ -1412,6 +1420,13 @@ ...@@ -1412,6 +1420,13 @@
" <td>NaN</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n",
" <th>x</th>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
...@@ -1419,9 +1434,10 @@ ...@@ -1419,9 +1434,10 @@
"text/plain": [ "text/plain": [
" one two three flag\n", " one two three flag\n",
"a 1.0 1.0 1.0 False\n", "a 1.0 1.0 1.0 False\n",
"b 2.0 2.0 4.0 False\n", "b 2.0 NaN NaN False\n",
"c 3.0 3.0 9.0 True\n", "c 3.0 3.0 9.0 True\n",
"d NaN 4.0 NaN False" "d NaN 4.0 NaN False\n",
"x NaN 2.0 NaN False"
] ]
}, },
"execution_count": 56, "execution_count": 56,
...@@ -1504,6 +1520,11 @@ ...@@ -1504,6 +1520,11 @@
" <td>NaN</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n",
" <th>x</th>\n",
" <td>NaN</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
...@@ -1513,7 +1534,8 @@ ...@@ -1513,7 +1534,8 @@
"a 1.0 False\n", "a 1.0 False\n",
"b 2.0 False\n", "b 2.0 False\n",
"c 3.0 True\n", "c 3.0 True\n",
"d NaN False" "d NaN False\n",
"x NaN False"
] ]
}, },
"execution_count": 59, "execution_count": 59,
...@@ -1552,7 +1574,7 @@ ...@@ -1552,7 +1574,7 @@
" <tr style=\"text-align: right;\">\n", " <tr style=\"text-align: right;\">\n",
" <th></th>\n", " <th></th>\n",
" <th>one</th>\n", " <th>one</th>\n",
" <th>three</th>\n", " <th>two</th>\n",
" <th>flag</th>\n", " <th>flag</th>\n",
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
...@@ -1566,7 +1588,7 @@ ...@@ -1566,7 +1588,7 @@
" <tr>\n", " <tr>\n",
" <th>b</th>\n", " <th>b</th>\n",
" <td>2.0</td>\n", " <td>2.0</td>\n",
" <td>4.0</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
...@@ -1581,16 +1603,23 @@ ...@@ -1581,16 +1603,23 @@
" <td>NaN</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n",
" <th>x</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
], ],
"text/plain": [ "text/plain": [
" one three flag\n", " one two flag\n",
"a 1.0 1.0 False\n", "a 1.0 1.0 False\n",
"b 2.0 4.0 False\n", "b 2.0 NaN False\n",
"c 3.0 9.0 True\n", "c 3.0 9.0 True\n",
"d NaN NaN False" "d NaN NaN False\n",
"x NaN NaN False"
] ]
}, },
"execution_count": 60, "execution_count": 60,
...@@ -1599,7 +1628,8 @@ ...@@ -1599,7 +1628,8 @@
} }
], ],
"source": [ "source": [
"df.insert(1, \"three\", three)\n", "# inserta la columna three en la posición 1 bajo el nombre two\n",
"df.insert(1, \"two\", three)\n",
"df" "df"
] ]
}, },
...@@ -1621,19 +1651,19 @@ ...@@ -1621,19 +1651,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 61,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"one 1\n", "one 1\n",
"three 1\n", "two 1\n",
"flag False\n", "flag False\n",
"Name: a, dtype: object" "Name: a, dtype: object"
] ]
}, },
"execution_count": 62, "execution_count": 61,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1644,19 +1674,19 @@ ...@@ -1644,19 +1674,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 63, "execution_count": 62,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"one 3\n", "one 3\n",
"three 9\n", "two 9\n",
"flag True\n", "flag True\n",
"Name: c, dtype: object" "Name: c, dtype: object"
] ]
}, },
"execution_count": 63, "execution_count": 62,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1667,7 +1697,7 @@ ...@@ -1667,7 +1697,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 65, "execution_count": 63,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1692,7 +1722,7 @@ ...@@ -1692,7 +1722,7 @@
" <tr style=\"text-align: right;\">\n", " <tr style=\"text-align: right;\">\n",
" <th></th>\n", " <th></th>\n",
" <th>one</th>\n", " <th>one</th>\n",
" <th>three</th>\n", " <th>two</th>\n",
" <th>flag</th>\n", " <th>flag</th>\n",
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
...@@ -1706,7 +1736,7 @@ ...@@ -1706,7 +1736,7 @@
" <tr>\n", " <tr>\n",
" <th>b</th>\n", " <th>b</th>\n",
" <td>2.0</td>\n", " <td>2.0</td>\n",
" <td>4.0</td>\n", " <td>NaN</td>\n",
" <td>False</td>\n", " <td>False</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
...@@ -1714,12 +1744,12 @@ ...@@ -1714,12 +1744,12 @@
"</div>" "</div>"
], ],
"text/plain": [ "text/plain": [
" one three flag\n", " one two flag\n",
"a 1.0 1.0 False\n", "a 1.0 1.0 False\n",
"b 2.0 4.0 False" "b 2.0 NaN False"
] ]
}, },
"execution_count": 65, "execution_count": 63,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1733,12 +1763,12 @@ ...@@ -1733,12 +1763,12 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 5.4 Ejercicios\n", "## 5.4 Ejercicios\n",
"Los siguentes ejercicios de realizann con los dato de *iris.csv *" "Los siguentes ejercicios de realizann con los dato de *iris.csv*"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 71, "execution_count": 64,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1823,7 +1853,7 @@ ...@@ -1823,7 +1853,7 @@
"4 5.0 3.6 1.4 0.2 setosa" "4 5.0 3.6 1.4 0.2 setosa"
] ]
}, },
"execution_count": 71, "execution_count": 64,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2 ScyPy\n",
"## 2.3 Algebra Lineal"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.4 Estadistica"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8rc1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.8rc1" "version": "3.5.3"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
```bash ```bash
sudo apt-get install python3 pip3 sudo apt-get install python3 pip3
python3 -m pip install --upgrade pip python3 -m pip install --upgrade pip
pip3 install jupyter pip3 install jupyter numpy pandas matplotlib sklearn
``` ```
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3. Programacion Orientada a Objetos\n",
"## 3.1 Clases \n",
"\n",
"Las clases proporcionan un medio de agrupar datos y funcionalidad. La creación de una nueva clase crea un nuevo tipo de objeto, lo que permite crear nuevas instancias de ese objeto. Cada instancia de la clase puede tener atributos adjuntos para mantener su estado. Las instancias de clase también pueden tener métodos (definidos por su clase) para modificar su estado."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"class Dog:\n",
" tricks = [] # Variable de clase\n",
" kind = 'canine' # Variable de clase\n",
" def __init__(self, name): # Constructor de clase\n",
" self.name = name # Variable de instancia\n",
" def add_trick(self, trick):\n",
" self.tricks.append(trick)\n",
" def f(self):\n",
" var=1 # variable local al método\n",
" return var"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pastis\n"
]
}
],
"source": [
"pastis=Dog(\"pastis\")\n",
"print(pastis.name)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'canine'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Dog.kind\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "type object 'Dog' has no attribute 'name'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-629675d46941>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mDog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: type object 'Dog' has no attribute 'name'"
]
}
],
"source": [
"Dog.name"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Max'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Dog(\"Max\").name"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"Max = Dog(\"Max\")\n",
"Keeper = Dog(\"Keeper\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'canine'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Max.kind"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'canine'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Max.kind=\"felis\"\n",
"Keeper.kind"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['roll over', 'play dead']"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Max.add_trick('roll over')\n",
"Max.add_trick('play dead')\n",
"Keeper.tricks\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"class Dog:\n",
" __kind = 'canine' # Variable de clase Privada\n",
" name = \"\"\n",
" def __init__(self, name):\n",
" self.name = name # Variable de instancia\n",
" self.tricks = [] # Variable de instancia\n",
" def add_trick(self, trick):\n",
" self.tricks.append(trick)\n",
" def get_kind(self):\n",
" return self.__kind"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "type object 'Dog' has no attribute '__kind'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-9-4cb7b0dc9a4d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mDog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__kind\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: type object 'Dog' has no attribute '__kind'"
]
}
],
"source": [
"Dog.__kind"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'canine'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Max = Dog(\"Max\")\n",
"Max.get_kind()\n",
"Max._Dog__kind\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notas:\n",
"* **Self** no es una palabra reservada en Python solo una convencion.\n",
"* [\"why explicit self has to stay\", por Guido van Rossum](http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html)\n",
"* [We are all consenting adults](https://python-guide-chinese.readthedocs.io/zh_CN/latest/writing/style.html#we-are-all-consenting-adults) Python permite muchos trucos, y algunos de ellos son potencialmente peligrosos. Un buen ejemplo es que cualquier código de cliente puede anular las propiedades y los métodos de un objeto: no hay una palabra clave \"privada\" en Python. Esta filosofía, muy diferente de los lenguajes altamente defensivos como Java, que ofrecen muchos mecanismos para evitar cualquier uso indebido, se expresa con el dicho: \"Todos somos adultos\".\n",
"\n",
"## 3.3 Decoradores \n",
"Los decoradores son una conveniencia sintáctica, que permite que un archivo fuente de Python diga qué va a hacer con el resultado de una función o una declaración de clase antes de la declaración.\n",
"\n",
"### 3.3.1 Metodos Estaticos\n",
"**@staticmethod**\n",
"Los metodos estatcos no requieren que exista una instancia de la clase y no conocen nada sobre la clase solo sus parametros de entrada.\n",
"\n",
"\n",
"### 3.3.2 Metodos de Clase\n",
"**@classmethod** Los metodos de clase n requiren que exista a una instancia de la clase y tiene acceso a las variables de clase y solo toman como entrada un unico parametro.\n",
"\n",
"### 3.3.2 Destructor\n",
"En Python, los destructores no son tan necesarios como en C ++ porque Python tiene un recolector de basura que maneja la administración de la memoria automáticamente.\n",
"El método **__del __ ()** es el método conocido como destructor en Python. Se llama cuando todas las referencias al objeto se han eliminado, es decir, cuando un objeto se recolecta como basura."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"class Dog:\n",
" __kind = 'Canis Lupus' # Variable de clase Privada\n",
" def __init__(self, name):\n",
" self.name = name # Variable de instancia\n",
" self.tricks = [] # Variable de instancia\n",
" def add_trick(self, trick):\n",
" self.tricks.append(trick)\n",
" @classmethod\n",
" def get_kind(cls):\n",
" return cls.__kind\n",
" @staticmethod\n",
" def bark(times):\n",
" print(\"Guau \"*times)\n",
" def __str__(self):\n",
" return self.name + \" es un \" + self.__kind\n",
" def __del__(self): \n",
" print(self.name + \" a muerto\") "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau Guau \n"
]
}
],
"source": [
"Dog.bark(30)\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Canis Lupus'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Dog.get_kind()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.4 Herencia"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"class Pet():\n",
" def __init__(self, owner_name):\n",
" self.owner=owner_name"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"class Malinois(Dog, Pet):\n",
" __breed = \"Malinois\"\n",
" def __init__(self, name, ownername):\n",
" Dog.__init__(self, name)\n",
" Pet.__init__(self, ownername)\n",
" self.tricks = [\"Fetch\"] # Variable de instancia\n",
" def fetch(self):\n",
" print(\"fetch\")\n",
" def __str__(self): #Overriding\n",
" # Obteniendo variable privada de la clase Padre\n",
" return self.name + \" es un \" + self._Dog__kind + \" de raza \" + self.__breed"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Canis Lupus\n",
"Max\n",
"['Fetch']\n",
"Alex\n",
"Max a muerto\n"
]
}
],
"source": [
"max = Malinois(\"Max\", \"Alex\")\n",
"print(max.get_kind())\n",
"print(max.name)\n",
"print(max.tricks)\n",
"print(max.owner)\n",
"del(max)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.5 Polimorfismo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.7 Ejercicios\n",
"Como recordarán, el proyecto final consiste en desarrollar un periódico inteligente en el cual, un usuario podrá elegir ciertos temas de interés personal, por ejemplo: ”Política de relaciones exteriores”, ”Francia”, ”Música”, ”Pearl Jam”; y el sistema colectará noticias de diversas fuentes y deberá procesar los documentos para determinar la relevancia de los mismos con respecto a los temas de interés del usuario.\n",
"\n",
"**Instrucciones**: Lea con atención las siguientes especificaciones y diseñe las clases descritas a continuación.\n",
"Diseñe en pyhton las clases siguientes de manera que contengan los atributos y comportamientos necesarios para ser incluidas como parte del proyecto \"periódico inteligente\". No es necesario que implemente los métodos de las clases pero sí es necesario que los declare aunque estén vacios, es decir, el esqueleto de las clases. Considere el uso de los siguientes conceptos:\n",
"\n",
"* constructor\n",
"* variables de instancia\n",
"* variable de clase\n",
"* métodos de instancia\n",
"* métodos de clase\n",
"* herencia\n",
"* polimorfismo\n",
"\n",
"Además de estas clases, puede incluir algunas otras clases que considere necesario incluyendo la justificación. \n",
"\n",
"### 3.7.1 La Clase Nota\n",
"La clase Nota debe abstraer el concepto de una nota periodística; una noticia que aparece en alguna fuente informativa. Algunas características principales de las Notas es que debe pertenecer a alguna categoría como \"deportes\" o \"cultura\", deben tener un título, un autor, una fecha de publicación, entre otros atributos.\n",
"### 3.7.2 La Clase Fuente\n",
"La clase Fuente debe abstraer el concepto de una fuente informativa como por ejemplo \"La Jornada\" o \"noticias MVS\". Una característica principal de las Fuentes es que generan Notas (ver ejercicio 1). \n",
"### 3.7.3 La Clase Editor\n",
"La clase Editor debe abstraer el concepto de una persona (o robot) que se encarga de recopilar las Notas de diversas Fuentes para un determinado tema (sección). Por ejemplo un Editor de la sección \"cultura\" debe ser capaz de identificar las notas que corresponden a este tema. También debe ser capaz de consultar las Fuentes y autores que proporcionan las mejores Notas para la sección que le corresponde, es decir, es experto en uno de los temas. \n",
"### 3.7.4 La Clase Editorial\n",
"La clase Editorial debe abstraer el concepto del consejo editorial de un periódico. Es una clase muy importante para el proyecto ya que la Editorial decide cuáles notas deben aparecer en el día y determina el grado de relevancia de las notas del día para cada sección.Para ello, debe interactuar con los Reporteros para decidir las notas que deben incluirse, considerando los temas de interés y las valoraciones de los Reporteros."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment