{"id":941,"date":"2020-11-05T00:33:11","date_gmt":"2020-11-05T00:33:11","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=941"},"modified":"2025-03-27T13:39:04","modified_gmt":"2025-03-27T13:39:04","slug":"python-variable-scopes","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/advanced-python\/python-variable-scopes\/","title":{"rendered":"Python Variable Scopes"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how Python variable scopes work. After the tutorial, you&#8217;ll have a good understanding of built-in, local, and global scopes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-python-variable-scopes'>Introduction to Python variable scopes <a href=\"#introduction-to-python-variable-scopes\" class=\"anchor\" id=\"introduction-to-python-variable-scopes\" title=\"Anchor for Introduction to Python variable scopes\">#<\/a><\/h2>\n\n\n\n<p>When you assign an object to a <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-variables\/\">variable<\/a>, the variable will <a href=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-references\/\">reference<\/a> that object in the memory. It&#8217;s saying that the variable is bound to the object.<\/p>\n\n\n\n<p>After the assignment, you can access the object using the variable name in various parts of your code. However, you cannot access the variable everywhere in the code.<\/p>\n\n\n\n<p>The variable name and its binding (name and object) only exist in specific parts of your code.<\/p>\n\n\n\n<p>The part of the code where you define the name\/binding is called the <strong>lexical scope<\/strong> of the variables.<\/p>\n\n\n\n<p>Python stores these bindings in something called namespaces. Every scope has its own namespace.<\/p>\n\n\n\n<p>You can think that a namespace is a table which contains the label and the reference that the label is bound to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='global-scopes'>Global scopes <a href=\"#global-scopes\" class=\"anchor\" id=\"global-scopes\" title=\"Anchor for Global scopes\">#<\/a><\/h2>\n\n\n\n<p>The global scope is the <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-module\/\">module<\/a> scope. The global scope spans a single Python source code file only.<\/p>\n\n\n\n<p>Python doesn&#8217;t have a truly global scope that spans across all modules except for the built-in scope.<\/p>\n\n\n\n<p>The built-in scope is a special scope that provides globally available objects such as <code>print<\/code>, <code>len<\/code>, <code>None<\/code>, <code>True<\/code>, and <code>False<\/code>.<\/p>\n\n\n\n<p>Basically, the built-in and global variables exist everywhere inside a module.<\/p>\n\n\n\n<p>Internally, global scopes are nested inside the built-in scope:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"441\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Variable-Scopes.png\" alt=\"Python Variable Scopes\" class=\"wp-image-945\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Variable-Scopes.png 661w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Variable-Scopes-300x200.png 300w\" sizes=\"auto, (max-width: 661px) 100vw, 661px\" \/><\/figure>\n<\/div>\n\n\n<p>If you access a variable from a scope and Python doesn&#8217;t find it in the namespace of that scope, it&#8217;ll search in the enclosing scope&#8217;s namespace.<\/p>\n\n\n\n<p>Suppose that you have the following statement in a module called <code>app.py<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">print(<span class=\"hljs-string\">'Hello'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this <code>app.py<\/code> module, Python looks for the <code>print<\/code> function in the module scope (<code>app.py<\/code>).<\/p>\n\n\n\n<p>Since Python doesn&#8217;t find the definition of the <code>print<\/code> function in the <code>app.py<\/code> module scope, Python goes up to the enclosing scope, which is the built-in scope, and looks for the <code>print<\/code> function there. In this case, it can find the <code>print<\/code> function in the built-in scope.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"634\" height=\"421\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Built-in-Scope.png\" alt=\"Python Built-in Scope\" class=\"wp-image-947\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Built-in-Scope.png 634w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Built-in-Scope-300x199.png 300w\" sizes=\"auto, (max-width: 634px) 100vw, 634px\" \/><\/figure>\n<\/div>\n\n\n<p>If you change the statement to the following, you&#8217;ll get an runtime error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">print(counter)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, Python doesn&#8217;t find the <code>counter<\/code> in the current global scope. Therefore, Python looks for it in the enclosing scope, which is the built-in scope.<\/p>\n\n\n\n<p>However, the variable <code>counter<\/code> doesn&#8217;t exist in the built-in scope. Therefore, Python issues a <code>NameError<\/code> exception:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Shell Session\" data-shcb-language-slug=\"shell\"><span><code class=\"hljs language-shell\">NameError: name 'counter' is not defined<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Shell Session<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">shell<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='local-scopes'>Local scopes <a href=\"#local-scopes\" class=\"anchor\" id=\"local-scopes\" title=\"Anchor for Local scopes\">#<\/a><\/h2>\n\n\n\n<p>When creating a <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-functions\/\">function<\/a>, you can define parameters and variables for the function. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">increment<\/span><span class=\"hljs-params\">(counter, by=<span class=\"hljs-number\">1<\/span>)<\/span>:<\/span>\n    result = counter + by\n    <span class=\"hljs-keyword\">return<\/span> result<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When you execute the code, Python carries two phases: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compilation <\/li>\n\n\n\n<li>Execution<\/li>\n<\/ul>\n\n\n\n<p>When Python compiles the file, it adds the <code>increment<\/code> function to the global scope. In addition, Python determines that the <code>counter<\/code>, <code>by<\/code>, and <code>result<\/code> variables inside the <code>increment()<\/code> function will be local to the <code>increment()<\/code> function. And Python won&#8217;t create the <code>counter<\/code>, <code>by<\/code> and <code>result<\/code> variables until the function is executed.<\/p>\n\n\n\n<p>Every time you call a function, Python creates a new scope. Python also assigns the variables defined inside the function to that scope. And this scope is called a <strong>function local scope<\/strong> or <strong>local scope<\/strong>.<\/p>\n\n\n\n<p>In our example, when you call the <code>increment()<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">increment(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>&#8230; Python creates a local scope for the <code>increment()<\/code> function call.<\/p>\n\n\n\n<p>Additionally, Python creates local variables <code>counter<\/code>, <code>by<\/code>, and <code>result<\/code> in the local namespace and binds them to values <code>10<\/code>, <code>2<\/code>, and <code>12<\/code>.<\/p>\n\n\n\n<p>When the function completes, Python will delete the local scope. And all the local variables such as <code>counter<\/code>, <code>by<\/code>, and <code>result<\/code> variables are out of scope. If you attempt to access these variables from outside the <code>increment()<\/code> function, you&#8217;ll get an error.<\/p>\n\n\n\n<p>If you call the <code>increment()<\/code> function again:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">increment(<span class=\"hljs-number\">100<\/span>,<span class=\"hljs-number\">3<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>&#8230; Python creates a new local scope and variables including <code>counter<\/code>, <code>by<\/code> and <code>result<\/code>, and binds them to values <code>100<\/code>, <code>3<\/code>, and <code>103<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='variable-lookups'>Variable lookups <a href=\"#variable-lookups\" class=\"anchor\" id=\"variable-lookups\" title=\"Anchor for Variable lookups\">#<\/a><\/h2>\n\n\n\n<p>In Python, scopes are nested. For example, local scopes are nested inside a module scope. Module scopes are nested inside the built-scope:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"634\" height=\"421\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Nested-Scopes.png\" alt=\"\" class=\"wp-image-948\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Nested-Scopes.png 634w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/11\/Python-Nested-Scopes-300x199.png 300w\" sizes=\"auto, (max-width: 634px) 100vw, 634px\" \/><\/figure>\n<\/div>\n\n\n<p>When you access an object bound to a variable, Python tries to find the object:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>in the current local scope first.<\/li>\n\n\n\n<li>and goes up the chain of enclosing scopes if Python doesn&#8217;t find the object in the current scope.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='the-global-keyword'>The global keyword <a href=\"#the-global-keyword\" class=\"anchor\" id=\"the-global-keyword\" title=\"Anchor for The global keyword\">#<\/a><\/h2>\n\n\n\n<p>When you retrieve the value of a global variable from inside a function, Python automatically searches the local scope&#8217;s namespace and up the chain of all enclosing scope namespaces. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">counter = <span class=\"hljs-number\">10<\/span>\n\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">current<\/span><span class=\"hljs-params\">()<\/span>:<\/span>\n    print(counter)\n\n\ncurrent()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y291bnRlciA9IDEwCgoKZGVmIGN1cnJlbnQoKToKICAgIHByaW50KGNvdW50ZXIpCgoKY3VycmVudCgp\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example, when the <code>current()<\/code> function is running, Python looks for the <code>counter<\/code> variable in the local scope.<\/p>\n\n\n\n<p>Since Python doesn&#8217;t find the variable, it searches for the variable in the global scope. And Python can find the <code>counter<\/code> variable in the global scope in this case.<\/p>\n\n\n\n<p>However, if you assign a value to a global variable from inside a function, Python will place that variable into the local namespace instead. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">counter = <span class=\"hljs-number\">10<\/span>\n\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">()<\/span>:<\/span>\n    counter = <span class=\"hljs-number\">0<\/span>\n    print(counter)\n\n\nreset()\nprint(counter)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y291bnRlciA9IDEwCgoKZGVmIHJlc2V0KCk6CiAgICBjb3VudGVyID0gMAogICAgcHJpbnQoY291bnRlcikKCgpyZXNldCgpCnByaW50KGNvdW50ZXIp\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Shell Session\" data-shcb-language-slug=\"shell\"><span><code class=\"hljs language-shell\">0 \n10<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Shell Session<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">shell<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>At the compile time, Python interprets the <code>counter<\/code> as a local variable.<\/p>\n\n\n\n<p>When <code>reset()<\/code> function is running, Python finds the <code>counter<\/code> in the local scope. The <code>print(counter)<\/code> statement inside the <code>reset()<\/code> function shows the value of the <code>counter<\/code>, which is zero.<\/p>\n\n\n\n<p>When we print <code>counter<\/code> after the <code>reset()<\/code> function completes, it shows 10 instead.<\/p>\n\n\n\n<p>In this example, the local <code>counter<\/code> variable masks the global <code>counter<\/code> variable.<\/p>\n\n\n\n<p>If you want to access a global variable from inside a function, you can use the <code>global<\/code> keyword. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">counter = <span class=\"hljs-number\">10<\/span>\n\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">()<\/span>:<\/span>\n    <span class=\"hljs-keyword\">global<\/span> counter\n    counter = <span class=\"hljs-number\">0<\/span>\n    print(counter) <span class=\"hljs-comment\"># 0<\/span>\n\n\nreset()\n\nprint(counter) <span class=\"hljs-comment\"># 0<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y291bnRlciA9IDEwCgoKZGVmIHJlc2V0KCk6CiAgICBnbG9iYWwgY291bnRlcgogICAgY291bnRlciA9IDAKICAgIHByaW50KGNvdW50ZXIpICMgMAoKCnJlc2V0KCkKCnByaW50KGNvdW50ZXIpICMgMA%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">0\n0<\/code><\/span><\/pre>\n\n\n<p>In this example, the following statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">global<\/span> counter<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>&#8230;instructs Python that the <code>counter<\/code> variable is bound to the global scope, not the local scope.<\/p>\n\n\n\n<p>Note that it&#8217;s not a good practice to access the global variable inside a function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The scopes of variables are the parts of the code where you can access the variables.<\/li>\n\n\n\n<li>The built-in scope is accessible from everywhere.<\/li>\n\n\n\n<li>The global scope (or module scope) can be accessible from every part of the module.<\/li>\n\n\n\n<li>The local scope is accessible from inside a function.<\/li>\n\n\n\n<li>Python stores the objects and their bindings in the namespace of the scope.<\/li>\n\n\n\n<li>Python looks up an object in the current scope first and goes up to the enclosing scope if Python doesn&#8217;t find it.<\/li>\n\n\n\n<li>Python scopes are nested.<\/li>\n\n\n\n<li>Use the <code>global<\/code> keyword if you want to access a global variable from inside a function.<\/li>\n<\/ul>\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=\"941\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-variable-scopes\/\"\n\t\t\t\tdata-post-title=\"Python Variable Scopes\"\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=\"941\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/advanced-python\/python-variable-scopes\/\"\n\t\t\t\tdata-post-title=\"Python Variable Scopes\"\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>Summary: in this tutorial, you&#8217;ll learn how Python variable scopes work. After the tutorial, you&#8217;ll have a good understanding of built-in, local, and global scopes. Introduction to Python variable scopes # When you assign an object to a variable, the variable will reference that object in the memory. It&#8217;s saying that the variable is bound [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":757,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-941","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/941","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=941"}],"version-history":[{"count":1,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/941\/revisions"}],"predecessor-version":[{"id":7108,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/941\/revisions\/7108"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/757"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}