{"id":77769,"date":"2020-03-31T14:45:43","date_gmt":"2020-03-31T09:15:43","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77769"},"modified":"2024-08-22T17:50:56","modified_gmt":"2024-08-22T12:20:56","slug":"python-interpreter","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/","title":{"rendered":"The Python Interpreter &#8211; Time to Upgrade your Programming Skills"},"content":{"rendered":"<p>We have learned that Python is an interpreted language. But what does that mean? Essentially, it means that another program reads our source code and executes it line by line, from top to bottom. In Python, this &#8220;another program&#8221; is known as an interpreter. Simply put, an interpreter is a type of program that runs other programs. This interpreter can be implemented in various languages, such as C, Java, or even Python itself. The standard Python interpreter, known as CPython, is written in C.<\/p>\n<h3>How does Python Interpreter work?<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/how-python-interpreter-works.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77830\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/how-python-interpreter-works.jpg\" alt=\"\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<p>In a <strong>nutshell<\/strong>, when you write a <strong>Python code<\/strong>, the <strong>interpreter reads<\/strong> the <strong>program<\/strong> and <strong>executes<\/strong> the <strong>instructions <\/strong>therein.<\/p>\n<p>Let\u2019s look at Python interpreter\u2019s working through a<strong> programmer\u2019s view<\/strong>, and then through the <strong>Python interpreter\u2019s view<\/strong> itself..<\/p>\n<h3>The Programmer\u2019s View<\/h3>\n<p>We start by <strong>creating <\/strong>a <strong>Python Program<\/strong>, which is just a <strong>text file<\/strong> containing <strong>Python statements<\/strong> and ending with a <strong>.py extension.<\/strong><\/p>\n<p>For example, one of the <strong>simplest<\/strong> yet <strong>fully function Python program<\/strong> is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">print(\u2018Hello, World\u2019)<\/pre>\n<p>Yeah, that\u2019s it!<\/p>\n<p>That one statement forms a complete<strong> Python program<\/strong>. It will simply <strong>print<\/strong> a <strong>string<\/strong>, that is, the <strong>text<\/strong> that\u2019s <strong>written inside <\/strong>the <strong>quotes<\/strong>.<\/p>\n<p><strong>Code<\/strong> it yourself by opening up<strong> Python\u2019s IDLE<\/strong>. For this, you\u2019ll need to <strong>install Python\u2019s<\/strong> <strong>latest version<\/strong> on your computer. This should open up <strong>Python\u2019s shell<\/strong>.<\/p>\n<p><strong> Create<\/strong> a <strong>new file (CTRL + N)<\/strong> and <strong>write<\/strong> the<strong> code<\/strong> written above. Now <strong>save it<\/strong> by whatever name you wish, say <strong>hello.py.<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77824\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-1.png\" alt=\"\" width=\"973\" height=\"735\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77825\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-2.png\" alt=\"\" width=\"821\" height=\"371\" \/><\/a><\/p>\n<p>Now let\u2019s get the <strong>Python interpreter<\/strong> to <strong>execute<\/strong> our <strong>file<\/strong>.<\/p>\n<p>This simply means that the Python interpreter will <strong>run all the statements<\/strong> in your <strong>file<\/strong> from <strong>top to bottom<\/strong>, one after another.<\/p>\n<p>You can command the <strong>interpreter<\/strong> to <strong>execute <\/strong>your <strong>file<\/strong> by clicking on <strong>Run &gt; Run Module<\/strong> at the<strong> top <\/strong>of your <strong>file<\/strong>, or simply by pressing the <strong>F5<\/strong> key.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77828\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/python-interpreter-3.png\" alt=\"\" width=\"764\" height=\"150\" \/><\/a><\/p>\n<p>If everything goes right, you will see the text <strong>\u201cHello, World\u201d<\/strong> printed out in <strong>blue<\/strong> in your <strong>Python Shell<\/strong>.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77829\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/output.png\" alt=\"\" width=\"826\" height=\"165\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Hello, World<br \/>\n&gt;&gt;&gt;<\/div>\n<p>Easy, right?<\/p>\n<p>Now let\u2019s see what goes behind the <strong>execution<\/strong> of this <strong>simple one-line program<\/strong>.<\/p>\n<h3>The Interpreter\u2019s view<\/h3>\n<p>The <strong>brief description<\/strong> in the <strong>prior section<\/strong> was usually all that a <strong>Python programmer<\/strong> needs to know.<\/p>\n<p><strong>Type code<\/strong> into the <strong>text file<\/strong> and then <strong>run<\/strong> that <strong>file<\/strong> through the <strong>Python Interpreter<\/strong>.<\/p>\n<p>Under the hood, though, a bit <strong>more happens<\/strong>. Specifically, your <strong>code<\/strong> is first <strong>compiled<\/strong> to something called <strong>\u201cbyte code\u201d<\/strong> and then it is passed to a <strong>\u201cvirtual machine\u201d<\/strong>.<\/p>\n<p><strong>Byte code<\/strong> is basically a<strong> low-level representation<\/strong> of your <strong>source code<\/strong>. The <strong>source code<\/strong> is <strong>translated<\/strong> to <strong>byte code<\/strong> because byte code can <strong>run<\/strong> much more <strong>quickly<\/strong> than the original source code.<\/p>\n<p>The interpreter <strong>does not expose<\/strong> this translation process to the <strong>Python programmer<\/strong>.<\/p>\n<p>Now, this<strong> newly generated byte code<\/strong> goes off for <strong>execution<\/strong> to the<strong> Python Virtual Machine (PVM)<\/strong>. PVM is not a separate program, it is in fact always present as a <strong>part <\/strong>of<strong> Python\u2019s system<\/strong>.<\/p>\n<p>Python Virtual Machine is the <strong>runtime engine<\/strong> of <strong>Python<\/strong>. It goes through your <strong>byte code<\/strong> instructions <strong>one by one<\/strong> and carries out the <strong>operations stated<\/strong> in those <strong>instructions<\/strong>.<\/p>\n<p>Technically, the <strong>execution<\/strong> of your<strong> byte code<\/strong> by <strong>PVM<\/strong> is the \u2018Python Interpreter\u2019 last step<strong>.<\/strong><\/p>\n<h3>Summary<\/h3>\n<p>Here we came to the end of our <strong>Python Interpreter article<\/strong>.<\/p>\n<p>In this article, we learned how <strong>Python Interpreter<\/strong> <strong>executes<\/strong> a <strong>program written<\/strong> in <strong>Python<\/strong>. Unlike compiler, an interpreter executes the program <strong>line-by-line<\/strong>. We also saw how the interpreter takes care of all the <strong>internal execution<\/strong> <strong>details<\/strong> for us.<\/p>\n<p>That was all about the working of Python\u2019s interpreter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have learned that Python is an interpreted language. But what does that mean? Essentially, it means that another program reads our source code and executes it line by line, from top to bottom.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77830,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[2163,2164,2165,2166,2167],"class_list":["post-77769","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-cpython","tag-how-python-interpreter-works","tag-interpreter-in-python","tag-python-interpreter","tag-python-web-interpreter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Python Interpreter - Time to Upgrade your Programming Skills - TechVidvan<\/title>\n<meta name=\"description\" content=\"Get to know about Python Interpreter in detail with some coding examples. And learn how Python Interpreter executes a program line by line in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Python Interpreter - Time to Upgrade your Programming Skills - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Get to know about Python Interpreter in detail with some coding examples. And learn how Python Interpreter executes a program line by line in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-31T09:15:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-22T12:20:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Python Interpreter - Time to Upgrade your Programming Skills - TechVidvan","description":"Get to know about Python Interpreter in detail with some coding examples. And learn how Python Interpreter executes a program line by line in Python.","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:\/\/techvidvan.com\/tutorials\/python-interpreter\/","og_locale":"en_US","og_type":"article","og_title":"The Python Interpreter - Time to Upgrade your Programming Skills - TechVidvan","og_description":"Get to know about Python Interpreter in detail with some coding examples. And learn how Python Interpreter executes a program line by line in Python.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-03-31T09:15:43+00:00","article_modified_time":"2024-08-22T12:20:56+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"The Python Interpreter &#8211; Time to Upgrade your Programming Skills","datePublished":"2020-03-31T09:15:43+00:00","dateModified":"2024-08-22T12:20:56+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/"},"wordCount":610,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg","keywords":["CPython","How Python Interpreter works","Interpreter in Python","python interpreter","Python web Interpreter"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/","url":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/","name":"The Python Interpreter - Time to Upgrade your Programming Skills - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg","datePublished":"2020-03-31T09:15:43+00:00","dateModified":"2024-08-22T12:20:56+00:00","description":"Get to know about Python Interpreter in detail with some coding examples. And learn how Python Interpreter executes a program line by line in Python.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-interpreter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/how-python-interpreter-works.jpg","width":802,"height":420,"caption":"how python interpreter work"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-interpreter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"The Python Interpreter &#8211; Time to Upgrade your Programming Skills"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77769"}],"version-history":[{"count":1,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77769\/revisions"}],"predecessor-version":[{"id":447667,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77769\/revisions\/447667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77830"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}