{"id":22136,"date":"2023-02-22T06:08:38","date_gmt":"2023-02-22T06:08:38","guid":{"rendered":"https:\/\/www.booksofall.com\/?post_type=product&#038;p=22136"},"modified":"2023-02-22T06:09:23","modified_gmt":"2023-02-22T06:09:23","slug":"a-guide-to-pythons-magic-methods","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/","title":{"rendered":"A Guide to Python&#8217;s Magic Methods"},"content":{"rendered":"<h4>Introduction<\/h4>\n<p>This guide is the culmination of a few months\u2019 worths of blog posts. The subject is magic methods.<\/p>\n<p>What are <a href=\"https:\/\/www.php.net\/manual\/en\/language.oop5.magic.php\">magic methods<\/a>? They\u2019re everything in object-oriented <a href=\"https:\/\/www.python.org\/\">Python<\/a>. They\u2019re special methods that you can define to add \u201dmagic\u201d to your classes. They\u2019re always surrounded by double underscores (e.g. __init__ or __lt__). They\u2019re also not as well documented as they need to be. All of the magic methods for Python appear in the same section in the Python docs, but they\u2019re scattered about and only loosely organized. There\u2019s hardly an example to be found in that section (and that may very well be by design, since they\u2019re all detailed in the<a href=\"https:\/\/www.oxfordreference.com\/page\/133\"> language reference<\/a>, along with boring syntax descriptions, etc.).<\/p>\n<p>So, to fix what I perceived as a flaw in <a href=\"https:\/\/docs.python.org\/\">Python\u2019s documentation<\/a>, I set out to provide some more plain English, example-driven documentation for Python\u2019s magic methods. I started out with weekly blog posts, and now that I\u2019ve finished with those, I\u2019ve put together this guide.<\/p>\n<p>I hope you enjoy it. Use it as a tutorial, a refresher, or a reference; it\u2019s just intended to be a user-friendly guide to <a href=\"https:\/\/www.tutorialsteacher.com\/python\/magic-methods-in-python#:~:text=Magic%20methods%20in%20Python%20are,class%20on%20a%20certain%20action.\">Python\u2019s magic methods<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 700px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/magicmethods-19l7gdt65y?enforceShowPromotionBar=true&amp;p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":22142,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":""},"product_brand":[],"product_cat":[275],"product_tag":[],"class_list":{"0":"post-22136","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-python","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Guide to Python&#039;s Magic Methods - BooksOfAll Portuguese<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Guide to Python&#039;s Magic Methods - BooksOfAll Portuguese\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Portuguese\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-22T06:09:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\" \/><meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\" \/>\n\t<meta property=\"og:image:width\" content=\"559\" \/>\n\t<meta property=\"og:image:height\" content=\"746\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\" \/>\n<meta name=\"twitter:label1\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/\",\"url\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/\",\"name\":\"A Guide to Python's Magic Methods - BooksOfAll Portuguese\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\",\"datePublished\":\"2023-02-22T06:08:38+00:00\",\"dateModified\":\"2023-02-22T06:09:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png\",\"width\":\"559\",\"height\":\"746\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/pt\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"A Guide to Python&#8217;s Magic Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#website\",\"url\":\"https:\/\/www.booksofall.com\/pt\/\",\"name\":\"BooksOfAll Portuguese\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/pt\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#organization\",\"name\":\"BooksOfAll Portuguese\",\"url\":\"https:\/\/www.booksofall.com\/pt\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Portuguese\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Guide to Python's Magic Methods - BooksOfAll Portuguese","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/","og_locale":"pt_PT","og_type":"article","og_title":"A Guide to Python's Magic Methods - BooksOfAll Portuguese","og_url":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/","og_site_name":"BooksOfAll Portuguese","article_modified_time":"2023-02-22T06:09:23+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","type":"","width":"","height":""},{"width":559,"height":746,"url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","twitter_misc":{"Tempo estimado de leitura":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/","url":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/","name":"A Guide to Python's Magic Methods - BooksOfAll Portuguese","isPartOf":{"@id":"https:\/\/www.booksofall.com\/pt\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","datePublished":"2023-02-22T06:08:38+00:00","dateModified":"2023-02-22T06:09:23+00:00","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#primaryimage","url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","contentUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/02\/img_63f5b01d128fd.png","width":"559","height":"746"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/pt\/a-guide-to-pythons-magic-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/pt\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/pt\/categories\/"},{"@type":"ListItem","position":3,"name":"A Guide to Python&#8217;s Magic Methods"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/pt\/#website","url":"https:\/\/www.booksofall.com\/pt\/","name":"BooksOfAll Portuguese","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/pt\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/pt\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-PT"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/pt\/#organization","name":"BooksOfAll Portuguese","url":"https:\/\/www.booksofall.com\/pt\/","logo":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Portuguese"},"image":{"@id":"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product\/22136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/media\/22142"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/media?parent=22136"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_brand?post=22136"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_cat?post=22136"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_tag?post=22136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}