<html> <h1>¿Qué aprenderemos hoy?</h1> <ul> <li>Herencia en programación orientada a objetos usando python </li> <ul> <h1>Requisitos</h1> <ul> <li>Ver el tutorial anterior: <a href="https://steemit.com/utopian-io/@greylml/programacion-orientada-a-objetos-python-1">Fuente</a> </li> <h1>Dificultad</h1> <ul> <li>Intermedia </li> <ul> <br> <center>https://steemitimages.com/DQmYLk4DBmYHhvJP6ki7qrrRx9EwcmZccgydws9YpAX2i7X/GREY%20SEGUNDO%20POST.png</center> <center>Fuente: propia (ilustración creada por @greylml)</center> <br> <div class="text-justify">Saludos a toda la comunidad Steemiana, una vez más con ustedes @greylml dandole continuidad a mi sesión de tutoriales de python donde les muestro fundamentos básicos del paradigma de programación orientado a objetos, esta vez tocaremos el tema de la herencia como mecanismo que sirve para crear clases nuevas a partir de clases ya existentes. Se podría decir que la herencia en programación funciona como en la vida real, una persona puede heredar de otra algún rasgo característico ya sea un lunar, habilidad o color de ojos, existen diversas características y en la programación funciona de manera que estas clases herederas (o mejor dicho clases derivadas) obtienen atributos y comportamientos de la clase vieja (o en este caso clase base) y se les modifica para modelar una nueva situación.</div> <br> <div class="text-justify">Para que vean que no les estoy cayendo a mentiras nos vamos a dirigir a nuestro sublime text y preparamos el entorno para desarrollar el programa, para efecto del proceso de heredar cosas tomaremos como ejemplo la habilidad que posee mi héroe favorito <strong>Megaman</strong> de simular los poderes que obtiene al vencer un robot master. Empezaremos creando la clase base con nuestra descripción de la misma y no olvides dejar los espacios correspondientes, son reglas básicas de sintaxis que describe nuestro libro <strong>Python para todos</strong>.</div> <br> <center>https://steemitimages.com/DQmVSy6dNiARrT1XeUCgRRqB9jUqaHjP1CXJpN8XyN7dAbr/herencia1.png</center> <br> <div class="text-justify">Ahora dentro de nuestra clase vamos a dejar un mensajito que especifique nada más que los que hereden de esta clase serán Heroes creados por el Dr. Light, luego vamos a definir nuestro método <strong>__init__</strong>que ya sabemos nos va a ejecutar automáticamente, por lo tanto las clases que hereden de la super clase RobotMaster tendremos que proporcionarle si es que tiene nuestro método init parámetros pues los valores a esos parámetros, en este caso así va a ser por eso añadimos nuestro self, que ya sabemos que es fijo y hace referencia al objeto, y luego vamos a añadir un valor que haga referencia a la habilidad que posee nuestro robot master.</div> <br> <center>https://steemitimages.com/DQmWG415V3Jm4jJmHEoSQYWJVXL3PhKebmkUiJJNhA4qkZz/herencia2.png</center> <br> <div class="text-justify">De momento no vamos a añadirle nada más a nuestra clase base, continuamos con nuestra subclase (la heredera) la voy a llamar megaman y dentro de sus paréntesis vamos a colocar de que clase queremos que herede, en este caso de la clase RobotMaster, ya con esto estamos diciendo que la clase megaman va a heredar atributos y métodos de nuestra super clase RobotMaster. Dentro de nuestra clase heredera vamos a definir otro método llamado nombre con un parámetro self, otro lllamado nombre y un tercer parámetro sera llamado robot_habilidad.</div> <br> <center>https://steemitimages.com/DQmYA83QYsHSQrP9HzRQ9somMos4f9x4L2oMMX4E8wKf7z6/herencia3.png</center> <br> <div class="text-justify">Vamos a imprimir un mensaje que diga el nombre del robot master y vamos a concatenar la variable nombre, luego vamos añadir otro mensaje que en este caso indicaría la habilidad que le corresponde a un robot master junto con el nombre que representa su habilidad. Como siguiente paso vamos a instanciar los objetos de la clase derivada megaman de manera que luego podamos acceder a sus atributos, lo haremos de la siguiente manera:</div> <br> <center>https://steemitimages.com/DQmXQFR71wWBHPxY2ANW4x2KBnDp1HdXqjckzLDyRUqJyXa/herencia4.png</center> <br> <div class="text-justify">He usado mis robotmasters favoritos de la saga, ahora vamos acceder a los métodos con la sintaxis objeto.método y lo haremos añadiendo un print para que haga un salto de línea, y dentro del print vamos a colocar 3 parámetros, de esta manera podremos ver como el programa nos permite ver la manera en que se obtienen los atributos de una clase main a una clase heredera, lo haremos de la siguiente manera: </div> <br> <center>https://steemitimages.com/DQmXPpwfuLuU9XNuVMKDxCgTqtMsUZnbP81xerDyVWCZE9B/herencia5.png</center> <br> <div class="text-justify">El resultado será este: </div> <br> <center>https://steemitimages.com/DQmNQj7LCjv1AhSQnpqjMWkRC9yhWrzBKuX1oZ8W1pok18f/herencia6.png</center> <br> <div class="text-justify">Como puedes ver el primer mensaje que nos imprime es "Heroes creados por el Dr.Light, esto debido a que la clase megaman a heredado todo lo que hay en la clase RobotMaster, luego podemos ver que nos imprime soy el robot master tenguman seguidamente de un none, eso es porque si no usamos la función return evidentemente no nos va a retornar ningún valor y por defecto será none. Luego nos imprime el resto de los robotmaster con su respectiva habilidad. La clase megaman es la heredera debido a que nuestro héroe al vencer estos robots siempre obtiene sus habilidades y me pareció que era un buen ejemplo que se podía adaptar a este tema. </div> <br> <center><h1>Despedida y bibliografía</h1></center> <br> <div class="text-justify">Bueno chicos esto ha sido todo, herencia es un tema bastante amplio y podemos darle continuidad a nuestro tema si lo desean, recuerden que la práctica hace al maestro, las buenas prácticas en python, sintaxis y temas de interés los puedes encontrar en el libro que dejaré más abajo. No olvides comentar tus dudas o lo que quieras y compartir o darme upvote si lo deseas, nos vemos en una próxima sesión de python, hasta pronto.</div> <br> <p>Libro: Python para todos</p> <p>Autor: Raúl González Duque</p> <br> <br> <center>https://steemitimages.com/DQmdrPZYkRxPur4x6Wber3iMgawkMz9VYmMj9b67nYW9v83/Manta1animacion.gif</center> </html>
author | greylml |
---|---|
permlink | programacion-orientada-a-objetos-python-2 |
category | spanish |
json_metadata | {"tags":["spanish","cervantes","programacion","python","tutorial"],"users":["greylml"],"image":["https://steemitimages.com/DQmYLk4DBmYHhvJP6ki7qrrRx9EwcmZccgydws9YpAX2i7X/GREY%20SEGUNDO%20POST.png","https://steemitimages.com/DQmVSy6dNiARrT1XeUCgRRqB9jUqaHjP1CXJpN8XyN7dAbr/herencia1.png","https://steemitimages.com/DQmWG415V3Jm4jJmHEoSQYWJVXL3PhKebmkUiJJNhA4qkZz/herencia2.png","https://steemitimages.com/DQmYA83QYsHSQrP9HzRQ9somMos4f9x4L2oMMX4E8wKf7z6/herencia3.png","https://steemitimages.com/DQmXQFR71wWBHPxY2ANW4x2KBnDp1HdXqjckzLDyRUqJyXa/herencia4.png","https://steemitimages.com/DQmXPpwfuLuU9XNuVMKDxCgTqtMsUZnbP81xerDyVWCZE9B/herencia5.png","https://steemitimages.com/DQmNQj7LCjv1AhSQnpqjMWkRC9yhWrzBKuX1oZ8W1pok18f/herencia6.png","https://steemitimages.com/DQmdrPZYkRxPur4x6Wber3iMgawkMz9VYmMj9b67nYW9v83/Manta1animacion.gif"],"links":["https://steemit.com/utopian-io/@greylml/programacion-orientada-a-objetos-python-1"],"app":"steemit/0.1","format":"html"} |
created | 2018-02-18 07:40:57 |
last_update | 2018-02-25 05:42:24 |
depth | 0 |
children | 4 |
last_payout | 2018-02-25 07:40:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 11.842 HBD |
curator_payout_value | 3.834 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6,250 |
author_reputation | 2,131,034,655,584 |
root_title | "Programación orientada a objetos: Python #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 38,451,297 |
net_rshares | 2,759,445,807,397 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
steemitboard | 0 | 296,479,326 | 1% | ||
qwasert | 0 | 117,233,861 | 0.1% | ||
minnowsupport | 0 | 0 | 0% | ||
buildawhale | 0 | 1,126,284,138,268 | 1.26% | ||
rayken04 | 0 | 73,220,771 | 10% | ||
upme | 0 | 1,541,132,717,908 | 1.34% | ||
brittuf | 0 | 83,415,206,483 | 61% | ||
hadro | 0 | 1,828,787,752 | 100% | ||
greylml | 0 | 613,391,044 | 100% | ||
hirothecookie | 0 | 614,885,154 | 100% | ||
josepxh | 0 | 454,167,311 | 90% | ||
areaemsono4 | 0 | 505,972,890 | 100% | ||
leninbracho50 | 0 | 381,474,789 | 100% | ||
series2688 | 0 | 472,505,154 | 100% | ||
ohmylove | 0 | 264,636,381 | 61% | ||
sliderax | 0 | 615,884,188 | 100% | ||
gaboroa14 | 0 | 583,778,179 | 100% | ||
zsh | 0 | 83,143,331 | 100% | ||
codebyte | 0 | 510,003,853 | 100% | ||
adalbertodrums | 0 | 583,732,736 | 100% | ||
rdr-cripto | 0 | 614,448,018 | 100% | ||
bonne | 0 | 0 | 100% |
You got a 1.26% upvote from @buildawhale courtesy of @greylml! If you believe this post is spam or abuse, please report it to our [Discord](https://discord.gg/yv2TMPu) #abuse channel. If you want to support our [Curation Digest](https://steemit.com/curation/@buildawhale/buildawhale-curation-digest-02-06-18) or our Spam & Abuse prevention efforts, please vote [@themarkymark](https://v2.steemconnect.com/sign/account-witness-vote?witness=themarkymark&approve=1) as witness.
author | buildawhale |
---|---|
permlink | re-greylml-programacion-orientada-a-objetos-python-2-20180219t005843328z |
category | spanish |
json_metadata | {"app":"postpromoter/1.8.4"} |
created | 2018-02-19 00:58:42 |
last_update | 2018-02-19 00:58:42 |
depth | 1 |
children | 0 |
last_payout | 2018-02-26 00:58:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 476 |
author_reputation | 26,331,497,086,830,538 |
root_title | "Programación orientada a objetos: Python #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 38,649,712 |
net_rshares | 0 |
<p>Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Greylml from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the <a href="https://discord.gg/HYj4yvw"> Peace, Abundance, and Liberty Network (PALnet) Discord Channel</a>. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.</p> <p>If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=102530.639667%20VESTS">50SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=205303.639667%20VESTS">100SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=514303.639667%20VESTS">250SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=1025303.639667%20VESTS">500SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=2053030.639667%20VESTS">1000SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=10253030.639667%20VESTS">5000SP</a>. <br><strong>Be sure to leave at least 50SP undelegated on your account.</strong></p>
author | minnowsupport |
---|---|
permlink | re-programacion-orientada-a-objetos-python-2-20180219t001654 |
category | spanish |
json_metadata | "" |
created | 2018-02-19 00:16:54 |
last_update | 2018-02-19 00:16:54 |
depth | 1 |
children | 0 |
last_payout | 2018-02-26 00:16:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,703 |
author_reputation | 148,902,805,319,183 |
root_title | "Programación orientada a objetos: Python #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 38,643,006 |
net_rshares | 0 |
Dear steemer, nice post and me followed u :L plz follow me back
author | sadbin |
---|---|
permlink | re-greylml-programacion-orientada-a-objetos-python-2-20180218t074137098z |
category | spanish |
json_metadata | {"tags":["spanish"],"app":"steemit/0.1"} |
created | 2018-02-18 07:41:39 |
last_update | 2018-02-18 07:41:39 |
depth | 1 |
children | 0 |
last_payout | 2018-02-25 07:41:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 64 |
author_reputation | 194,805,054,529 |
root_title | "Programación orientada a objetos: Python #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 38,451,412 |
net_rshares | 0 |
Congratulations @greylml! You have completed some achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@greylml) Award for the number of upvotes Click on any badge to view your own Board of Honor on SteemitBoard. For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard) If you no longer want to receive notifications, reply to this comment with the word `STOP` > By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
author | steemitboard |
---|---|
permlink | steemitboard-notify-greylml-20180219t014241000z |
category | spanish |
json_metadata | {"image":["https://steemitboard.com/img/notifications.png"]} |
created | 2018-02-19 01:42:39 |
last_update | 2018-02-19 01:42:39 |
depth | 1 |
children | 0 |
last_payout | 2018-02-26 01:42:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 684 |
author_reputation | 38,975,615,169,260 |
root_title | "Programación orientada a objetos: Python #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 38,657,303 |
net_rshares | 0 |