{"id":633,"date":"2021-02-25T09:13:58","date_gmt":"2021-02-25T03:43:58","guid":{"rendered":"https:\/\/cbsepython.in\/?p=633"},"modified":"2023-12-28T09:55:04","modified_gmt":"2023-12-28T04:25:04","slug":"first-python-program","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/first-python-program\/","title":{"rendered":"First Python Program &#8220;Hello Python&#8221;"},"content":{"rendered":"<h2><span style=\"color: #000000;\">Introduction<\/span><\/h2>\n<p><span style=\"color: #000000;\">Python is an interpreted language as its programs are executed by an interpreter. Thus, Python interpreter should be installed on the computer system to write and run Python programs. Python IDLE (Integrated Development and Learning Environment) provides two working modes-interactive mode (popularly known as Python shell) and script mode.<\/span><\/p>\n<blockquote><p><span style=\"color: #000000;\">The Python IDLE tool offers an interactive and a more efficient platform to write your code in Python.<\/span><\/p><\/blockquote>\n<p><span style=\"color: #000000;\">Using <span style=\"font-size: 14pt;\"><strong>Interactive (Python Shell window) mode<\/strong><\/span>, the Python commands are directly typed at &gt;&gt;&gt; (command prompt), and as soon as we press the Enter key, the interpreter displays the result(s) immediately, which is known as <span style=\"font-size: 14pt;\"><strong>Displaying<\/strong><\/span>.<\/span><\/p>\n<p><span style=\"color: #000000;\">For example,<\/span><\/p>\n<h2><span style=\"color: #000000;\">First Python Program<\/span><\/h2>\n<p><span style=\"color: #000000;\">Let us execute programs in different modes of programming.<\/span><\/p>\n<h3><span style=\"color: #000000;\">Interactive Mode Programming<\/span><\/h3>\n<p><span style=\"color: #000000;\">Invoking the interpreter without passing a script file as a parameter brings up the following prompt \u2212<\/span><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-710\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/02\/Welcome-300x77.jpg\" alt=\"\" width=\"790\" height=\"203\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/02\/Welcome-300x77.jpg 300w, https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/02\/Welcome.jpg 671w\" sizes=\"(max-width: 790px) 100vw, 790px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">Type the following text at the Python prompt and press the Enter \u2212<\/span><\/p>\n<p><span style=\"color: #000000;\">&gt;&gt;&gt; print &#8220;Hello, Python!&#8221;<\/span><\/p>\n<p><span style=\"color: #000000;\">If you are running new version of Python, then you would need to use print statement with parenthesis as in\u00a0<strong>print (&#8220;Hello, Python!&#8221;);<\/strong>. However in Python version 2.4.3, this produces the following result \u2212<\/span><\/p>\n<p><span style=\"color: #000000;\">Hello, Python!<\/span><\/p>\n<h3><span style=\"color: #000000;\">Script Mode Programming<\/span><\/h3>\n<p><span style=\"color: #000000;\">Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished. When the script is finished, the interpreter is no longer active.<\/span><\/p>\n<p><span style=\"color: #000000;\">Let us write a simple Python program in a script. Python files have extension\u00a0<strong>.py<\/strong>. Type the following source code in a test.py file \u2212<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">x=5\r\ny=3\r\nz=x+y\r\nz=z+3\r\nx=y\r\ny=5\r\nprint(\"The value of x is:\", x)\r\nprint(\"The value of y is:\", y)\r\nprint(\"The value of z is:\", z)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">We assume that you have Python interpreter set in PATH variable. Now, try to run this program as follows \u2212<\/span><\/p>\n<p><span style=\"color: #000000;\">$ python test.py<\/span><\/p>\n<p><span style=\"color: #000000;\">This produces the following result \u2212<\/span><\/p>\n<p><span style=\"color: #000000;\">(&#8216;The value of x is:&#8217;, 3)<\/span><br \/>\n<span style=\"color: #000000;\">(&#8216;The value of y is:&#8217;, 5)<\/span><br \/>\n<span style=\"color: #000000;\">(&#8216;The value of z is:&#8217;, 11)<\/span><br \/>\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Python is an interpreted language as its programs are executed by an interpreter. Thus, Python interpreter should be installed on the computer system to write and run Python programs. Python IDLE (Integrated Development and Learning Environment) provides two working modes-interactive mode (popularly known as Python shell) and script mode. The Python IDLE tool offers [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-633","post","type-post","status-publish","format-standard","hentry","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}