{"id":731,"date":"2024-04-14T10:54:47","date_gmt":"2024-04-14T10:54:47","guid":{"rendered":"https:\/\/javigomez.org\/?p=731"},"modified":"2025-09-29T20:33:15","modified_gmt":"2025-09-29T20:33:15","slug":"06-01-python-clases-atributos-y-metodos","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2024\/04\/14\/06-01-python-clases-atributos-y-metodos\/","title":{"rendered":"06.01 Python \u2013 Clases &#8211; Atributos  y m\u00e9todos"},"content":{"rendered":"\n<p>El constructor se define con el nombre de la funci\u00f3n __init__ y recibe, como m\u00ednimo un par\u00e1metro que es self. Este par\u00e1metro es&nbsp; una referencia al mismo objeto.<\/p>\n\n\n\n<p>Los m\u00e9todos de tipo, tambi\u00e9n conocidos como m\u00e9todos dunder, son m\u00e9todos que tienen dos guiones bajos (__) antes y despu\u00e9s de su nombre. Estos m\u00e9todos se utilizan para implementar m\u00e9todos especiales, como la comparaci\u00f3n, el manejo de excepciones y la impresi\u00f3n de objetos.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Persona:\n    def __init__(self):\n        self.nombre=\"Javi\"\n        self.edad=56\n\np=Persona()\n\np.nombre=\"Lara\"\nprint(p.nombre)\nprint(p.edad)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>class Persona:\n    def __init__(self,n,e):\n        self.nombre=n\n        self.edad= e\n\np=Persona(\"Javi\",56)\n\np.edad=35\n\nprint(p.nombre)\nprint(p.edad)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>class Persona:\n    def __init__(self,n,e):\n        self.nombre=n\n        self.edad= e\n\n    def mostrar(self):\n        print(f\"Nombre: {self.nombre} - edad: {self.edad}\")\n\np=Persona(\"Javi\",56)\n\np.edad=35\n\np.mostrar()\n\nPersona.mostrar(p)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"PYTHON U06 01 Clases Attr Metodos Constructor\" width=\"1200\" height=\"900\" src=\"https:\/\/www.youtube.com\/embed\/NfXENoFUqnk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>El constructor se define con el nombre de la funci\u00f3n __init__ y recibe, como m\u00ednimo un par\u00e1metro que es self. Este par\u00e1metro es&nbsp; una referencia &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[79,277],"class_list":["post-731","post","type-post","status-publish","format-standard","hentry","category-python","tag-clases","tag-python"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=731"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":862,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/731\/revisions\/862"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}