{"id":22136,"date":"2023-02-22T06:08:38","date_gmt":"2023-02-22T06:08:38","guid":{"rendered":"https:\/\/www.booksofall.com\/vi\/?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\/vi\/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 Vietnamese<\/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\/vi\/a-guide-to-pythons-magic-methods\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Guide to Python&#039;s Magic Methods - BooksOfAll Vietnamese\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Vietnamese\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-22T06:09:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png\" \/>\n<meta name=\"twitter:label1\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 ph\u00fat\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/\",\"url\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/\",\"name\":\"A Guide to Python's Magic Methods - BooksOfAll Vietnamese\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/vi\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/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\/vi\/a-guide-to-pythons-magic-methods\/#breadcrumb\"},\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png\",\"width\":\"559\",\"height\":\"746\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/vi\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/vi\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"A Guide to Python&#8217;s Magic Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/#website\",\"url\":\"https:\/\/www.booksofall.com\/vi\/\",\"name\":\"BooksOfAll Vietnamese\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/vi\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/vi\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/#organization\",\"name\":\"BooksOfAll Vietnamese\",\"url\":\"https:\/\/www.booksofall.com\/vi\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\/\/www.booksofall.com\/vi\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Vietnamese\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/vi\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Guide to Python's Magic Methods - BooksOfAll Vietnamese","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\/vi\/a-guide-to-pythons-magic-methods\/","og_locale":"vi_VN","og_type":"article","og_title":"A Guide to Python's Magic Methods - BooksOfAll Vietnamese","og_url":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/","og_site_name":"BooksOfAll Vietnamese","article_modified_time":"2023-02-22T06:09:23+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png","twitter_misc":{"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"1 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/","url":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/","name":"A Guide to Python's Magic Methods - BooksOfAll Vietnamese","isPartOf":{"@id":"https:\/\/www.booksofall.com\/vi\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/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\/vi\/a-guide-to-pythons-magic-methods\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#primaryimage","url":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png","contentUrl":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2023\/02\/img_63f5b01d128fd.png","width":"559","height":"746"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/vi\/a-guide-to-pythons-magic-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/vi\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/vi\/categories\/"},{"@type":"ListItem","position":3,"name":"A Guide to Python&#8217;s Magic Methods"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/vi\/#website","url":"https:\/\/www.booksofall.com\/vi\/","name":"BooksOfAll Vietnamese","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/vi\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/vi\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/vi\/#organization","name":"BooksOfAll Vietnamese","url":"https:\/\/www.booksofall.com\/vi\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/www.booksofall.com\/vi\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/vi\/wp-content\/uploads\/sites\/10\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Vietnamese"},"image":{"@id":"https:\/\/www.booksofall.com\/vi\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/product\/22136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/media\/22142"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/media?parent=22136"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/product_brand?post=22136"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/product_cat?post=22136"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/vi\/wp-json\/wp\/v2\/product_tag?post=22136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}