<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4686,"date":"2022-08-16T07:57:34","date_gmt":"2022-08-16T07:57:34","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4686"},"modified":"2022-08-16T07:57:34","modified_gmt":"2022-08-16T07:57:34","slug":"what-is-scope-in-python","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/","title":{"rendered":"What is Scope in Python ?"},"content":{"rendered":"<ul>\n<li>Variables in python are the containers for storing data values.<\/li>\n<li>It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.<\/li>\n<li>Python is not statically typed, unlike other languages like C\/C++\/JAVA.<\/li>\n<li>Scope of a variable is the location where we can find a variable and also access it if required.<\/li>\n<li>In python there are four types of scopes they are, Local Scope, Global Scope, Enclosing Scope and Built-in Scope.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4688\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png\" alt=\"\" width=\"1029\" height=\"1009\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png 1029w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python-300x294.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python-1024x1004.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python-768x753.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python-390x382.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python-820x804.png 820w\" sizes=\"(max-width: 1029px) 100vw, 1029px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Global variables are the ones that are defined and declared outside, not specified to any function.<\/li>\n<li>In current function a local scope refers to the local objects were available.<\/li>\n<li>Global scope refers to the objects available throughout the code execution since their inception.<\/li>\n<li>In program a module-level scope refers to the global objects of the current module accessible.<\/li>\n<li>In program an\u00a0<strong>outermost scope <\/strong>refers to all the built-in names callable and objects in this scope are searched last to find the name referenced.<\/li>\n<\/ul>\n<h3 id=\"sample-code-global-scope\"><strong>Sample Code : Global Scope<\/strong><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-python code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-python code-embed-code\"># This function modifies global variable &#039;s&#039;<br\/>def f():<br\/>    global s<br\/>    print(s)<br\/>    s = &quot;Look for Wikitechy Python Section&quot;<br\/>    print(s)<br\/>   <br\/># Global Scope<br\/>s = &quot;Python is great !&quot;<br\/>f()<br\/>print(s)<\/code><\/pre> <\/div>\n<h3 id=\"output\">Output<\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4687\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope.png\" alt=\"\" width=\"1258\" height=\"337\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope.png 1258w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-300x80.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-1024x274.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-768x206.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-390x104.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-820x220.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/global-scope-1180x316.png 1180w\" sizes=\"(max-width: 1258px) 100vw, 1258px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance. Python is not statically typed, unlike other languages like C\/C++\/JAVA. Scope of a variable is the location where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[5608],"tags":[18138,18137,18135,18136,18139,18132,18146,18133,18134,18140,18141,18144,18143,18145,18142,18147],"class_list":["post-4686","post","type-post","status-publish","format-standard","hentry","category-python","tag-how-many-global-scopes-are-there-in-a-python-program","tag-local-and-global-scope-in-python","tag-python-scope-in-future","tag-python-scope-in-india","tag-python-scope-rules","tag-types-of-scope-in-python","tag-what-is-built-in-scope-in-python","tag-what-is-global-scope-in-python","tag-what-is-local-scope-in-python","tag-what-is-scope-in-python","tag-what-is-scope-resolution-in-python","tag-what-is-scope-what-is-the-scope-resolving-rule-in-python","tag-what-is-the-order-of-resolving-scope-of-a-name-in-a-python-program","tag-what-is-the-scope-of-global-variable-in-python","tag-what-is-the-scope-of-python-in-future","tag-what-is-the-scope-of-python-in-india"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Scope in Python - Python Scope of Variables - Wikitechy<\/title>\n<meta name=\"description\" content=\"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.\" \/>\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.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Scope in Python - Python Scope of Variables - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-16T07:57:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/\",\"name\":\"What is Scope in Python - Python Scope of Variables - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png\",\"datePublished\":\"2022-08-16T07:57:34+00:00\",\"dateModified\":\"2022-08-16T07:57:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png\",\"width\":1029,\"height\":1009},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Scope in Python - Python Scope of Variables - Wikitechy","description":"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.","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.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/","og_locale":"en_US","og_type":"article","og_title":"What is Scope in Python - Python Scope of Variables - Wikitechy","og_description":"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/","og_site_name":"Wikitechy","article_published_time":"2022-08-16T07:57:34+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/","name":"What is Scope in Python - Python Scope of Variables - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png","datePublished":"2022-08-16T07:57:34+00:00","dateModified":"2022-08-16T07:57:34+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Scope in Python ? - Variables in python are the containers for storing data values. It gets mapped to that instance, they are reference, or pointers, to an object in memory which means that whenever a variable is assigned to an instance.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-scope-in-python\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/scopes-in-python.png","width":1029,"height":1009},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4686"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4686\/revisions"}],"predecessor-version":[{"id":4689,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4686\/revisions\/4689"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}