{"id":757,"date":"2020-10-25T05:15:42","date_gmt":"2020-10-25T05:15:42","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=757"},"modified":"2025-03-27T13:59:44","modified_gmt":"2025-03-27T13:59:44","slug":"advanced-python","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/advanced-python\/","title":{"rendered":"Advanced Python"},"content":{"rendered":"\n<p>This tutorial series explains the advanced Python concepts and helps you understand how and why things work in Python under the hood.<\/p>\n\n\n\n<p>To learn advanced Python, you need to have <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/\">basic Python<\/a> knowledge and some practical experience in Python programming.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='variables-memory-management'>Section 1. Variables &amp; Memory Management <a href=\"#variables-memory-management\" class=\"anchor\" id=\"variables-memory-management\" title=\"Anchor for Section 1. Variables &amp; Memory Management\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-references\/\">References<\/a> &#8211; learn about references and how reference counting works in Python.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-garbage-collection\/\">Garbage collection<\/a> &#8211; understand the garbage collection and how to interact with Python Garbage collector via the <code>gc<\/code> module.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/dynamic-typing-in-python\/\">Dynamic typing<\/a> &#8211; explain to you how dynamic typing works and understand the differences between static types and dynamic types.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-mutable-and-immutable\/\">Mutable &amp; Immutable objects<\/a> &#8211; introduce you to mutable and immutable objects in Python.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-is-operator\/\">is operator<\/a> &#8211; help you understand object identity and equality, and how to use the <code>is<\/code> operator to check if two variables reference the same object.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-none\/\">None<\/a> &#8211; learn about the None object and how to use it properly.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='variable-scopes'>Section 2. Variable scopes <a href=\"#variable-scopes\" class=\"anchor\" id=\"variable-scopes\" title=\"Anchor for Section 2. Variable scopes\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-variable-scopes\/\">Variable scopes <\/a> &#8211; explain to you the variable scopes and help understand the built-in, local, and global variables.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-nonlocal\/\">Nonlocal scopes and nonlocal variables<\/a> &#8211; understand the nonlocal scopes and how to change variables of the nonlocal scopes using the nonlocal keyword.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='closures'>Section 3. Closures <a href=\"#closures\" class=\"anchor\" id=\"closures\" title=\"Anchor for Section 3. Closures\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-closures\/\">Closures<\/a> &#8211; help you understand the closures in Python and how to define closures.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='decorators'>Section 4. Decorators <a href=\"#decorators\" class=\"anchor\" id=\"decorators\" title=\"Anchor for Section 4. Decorators\">#<\/a><\/h2>\n\n\n\n<p>Decorators allow you to modify the behavior of functions, classes, and methods at runtime without making permanent changes to their original structure. In this section, you&#8217;ll learn what decorators are and how to use them effectively.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-decorators\/\">Decorators<\/a> &#8211; explain decorators and show you how to develop a simple decorator in Python.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-decorator-arguments\/\">Decorators with arguments<\/a> &#8211; show you how to define a decorator that accepts one or more arguments.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-class-decorators\/\">Class Decorators<\/a> &#8211; illustrate how to define a class as a decorator.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-monkey-patching\/\">Monkey Patching<\/a> &#8211; explain the monkey patching technique in Python and how to use decorators to implement monkey patching.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='named-tuples'>Section 5. Named Tuples <a href=\"#named-tuples\" class=\"anchor\" id=\"named-tuples\" title=\"Anchor for Section 5. Named Tuples\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-namedtuple\/\">Named Tuples<\/a> &#8211; learn how to use named tuples, which allow you to store data like classes, but without the need to define complete class structures.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='sequence-types'>Section 6. Sequence Types <a href=\"#sequence-types\" class=\"anchor\" id=\"sequence-types\" title=\"Anchor for Section 6. Sequence Types\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-sequences\/\">Sequence types<\/a> &#8211; learn about sequences and their basic operations<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-tuple-vs-list\/\">Lists vs. Tuples<\/a> &#8211; explain the main differences between the tuple and list.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-slicing\/\">Slicing<\/a> &#8211; show you how to use slicing to extract data from or assign data to a sequence.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-fibonacci-sequence\/\">Custom Sequence Type<\/a> &#8211; learn about the custom sequence type and show you how to use a custom sequence type to define the Fibonacci sequence.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='iterators-and-iterables'>Section 7. Iterators and Iterables <a href=\"#iterators-and-iterables\" class=\"anchor\" id=\"iterators-and-iterables\" title=\"Anchor for Section 7. Iterators and Iterables\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-iterators\/\">Iterators<\/a> &#8211; learn about the iterator protocol and how to define a custom iterator.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-iterator-vs-iterable\/\">Iterators vs. Iterables<\/a> &#8211; understand iterators and iterables, and the differences between them<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-iter\/\">iter()<\/a> &#8211; explain to you how the iter() function works and how to use it effectively.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='generators'>Section 8. Generators <a href=\"#generators\" class=\"anchor\" id=\"generators\" title=\"Anchor for Section 8. Generators\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-generators\/\">Generator functions<\/a> &#8211; introduce you to the generator functions and how to use generators to create iterators.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-generator-expressions\/\">Generator expressions<\/a> &#8211; show you an alternative syntax for creating a generator object.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='context-managers'>Section 9. Context Managers <a href=\"#context-managers\" class=\"anchor\" id=\"context-managers\" title=\"Anchor for Section 9. Context Managers\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-context-managers\/\">Context Managers<\/a> &#8211; learn about context managers and how to use them effectively.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='integer-types'>Section 10. Integer types <a href=\"#integer-types\" class=\"anchor\" id=\"integer-types\" title=\"Anchor for Section 10. Integer types\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-integers\/\">Integers<\/a> &#8211; learn about the integer and how Python stores the integers in the memory.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-floor-division\/\">Floor division operator (\/\/)<\/a>  &#8211; introduce you to the floor division operator (\/\/) and how to use it effectively.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-modulo\/\">Modulo operator (%)<\/a> &#8211; explain how the module operator (%) works in Python.<\/li>\n\n\n\n<li><code><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-bool\/\">bool<\/a><\/code> &#8211; explain how Python boolean works under the hood.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-and\/\">The <code>and<\/code> operator<\/a> &#8211; learn how to use the <code>and<\/code> operator effectively.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-or\/\">The <code>or<\/code> operator<\/a> &#8211; show you how to use the <code>or<\/code> operator.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='float'>Section 11. Float <a href=\"#float\" class=\"anchor\" id=\"float\" title=\"Anchor for Section 11. Float\">#<\/a><\/h2>\n\n\n\n<ul id=\"block-8c8708cf-3b49-482d-9e28-0b312da11438\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-float\/\">Float<\/a> &#8211; explain how Python represents floating-point numbers internally and how to test two floats for equality.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-float-to-int\/\">Converting float to int<\/a> &#8211; show you how to convert float to int.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-rounding\/\">Rounding<\/a> &#8211; learn how to round a floating-point number to a specified number of digits after the decimal point.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='decimal'>Section 12. Decimal <a href=\"#decimal\" class=\"anchor\" id=\"decimal\" title=\"Anchor for Section 12. Decimal\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-decimal\/\">Decimal<\/a> &#8211; learn about the <code>decimal<\/code> module that provides&nbsp;support for fast correctly-rounded decimal floating-point arithmetic.<\/li>\n<\/ul>\n<\/div><\/div>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"757\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/advanced-python\/\"\n\t\t\t\tdata-post-title=\"Advanced Python\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"757\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/advanced-python\/\"\n\t\t\t\tdata-post-title=\"Advanced Python\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This section covers the advanced Python concepts so that you understand how and why things works in Python.<\/p>\n","protected":false},"author":1,"featured_media":2391,"parent":0,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-757","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=757"}],"version-history":[{"count":3,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/757\/revisions"}],"predecessor-version":[{"id":7118,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/757\/revisions\/7118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media\/2391"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}