{"id":122,"date":"2023-06-02T19:23:26","date_gmt":"2023-06-02T19:23:26","guid":{"rendered":"http:\/\/python.garden\/index.php\/2023\/06\/02\/understanding-the-python-shell-and-writing-your-first-program\/"},"modified":"2023-06-02T19:32:41","modified_gmt":"2023-06-02T19:32:41","slug":"understanding-the-python-shell-and-writing-your-first-program","status":"publish","type":"post","link":"https:\/\/python.garden\/index.php\/2023\/06\/02\/understanding-the-python-shell-and-writing-your-first-program\/","title":{"rendered":"Chapter 1.2: Understanding the Python shell and writing your first program"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Learning the basics of Python shell and writing the first program<\/h1>\n\n\n\n<p>In the previous section, we walked through the process of installing Python and setting up a suitable Integrated Development Environment (IDE). With these tools in place, we are now ready to start coding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Python Shell<\/h2>\n\n\n\n<p>The Python shell is an interactive interpreter that allows us to run Python code line by line. It&#8217;s an excellent tool for testing out small snippets of code and debugging.<\/p>\n\n\n\n<p>Let&#8217;s open the Python shell. If you&#8217;re using an IDE like PyCharm or Visual Studio Code, the Python shell (also called the Python console) is usually available within the IDE. If you&#8217;ve installed Python directly, you can open the shell by typing <code>python<\/code> (or <code>python3<\/code> on some systems) in your terminal.<\/p>\n\n\n\n<p>In the Python shell, you should see something like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">Python 3.9.0 (default, Oct 5 2020, 00:00:00)\n[Clang 12.0.0 (clang-1200.0.32.27)] on darwin\nType &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.\n&gt;&gt;&gt;<\/pre><\/div>\n\n\n\n<p>The <code>&gt;&gt;&gt;<\/code> symbol is the Python prompt where we can type Python code.<\/p>\n\n\n\n<p>Let&#8217;s try a simple command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">&gt;&gt;&gt; print(&quot;Hello, Python shell!&quot;)\nHello, Python shell!<\/pre><\/div>\n\n\n\n<p>In the above example, we called Python&#8217;s built-in <code>print<\/code> function, which outputs the provided string to the console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Writing Your First Program<\/h2>\n\n\n\n<p>Now that we&#8217;ve gotten a taste of the Python shell, let&#8217;s write our first Python program.<\/p>\n\n\n\n<p>Python programs are simply text files with the extension <code>.py<\/code>. You can create a Python file in your chosen IDE or text editor.<\/p>\n\n\n\n<p>Let&#8217;s create a file called <code>hello_world.py<\/code> and write the following code in it:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">print(&quot;Hello, Python program!&quot;)<\/pre><\/div>\n\n\n\n<p>We&#8217;ve written our first Python program! To run it, navigate to the directory containing <code>hello_world.py<\/code> in your terminal and run the command <code>python hello_world.py<\/code> (or <code>python3 hello_world.py<\/code> if needed). The output should be:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">Hello, Python program!<\/pre><\/div>\n\n\n\n<p>Congratulations! You&#8217;ve now used the Python shell and written and run your first Python program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next Steps<\/h2>\n\n\n\n<p>In the following sections, we will discuss variables, data types, and operators. You&#8217;ll start to learn how to store and manipulate data in Python, which is the basis of all Python programming.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>This is a very basic introduction. As we progress further into Python, we&#8217;ll delve into more complex topics and create more elaborate programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learning the basics of Python shell and writing the first program In the previous section, we walked through the process of installing Python and setting up a suitable Integrated Development&hellip;<\/p>\n","protected":false},"author":1,"featured_media":137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[94,95,97],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-introduction-to-python-2","category-introduction-to-python-introduction-to-python-2","category-understanding-the-python-shell-and-writing-your-first-program"],"featured_image_src":"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/06\/Selection_1220.png?fit=594%2C91&ssl=1","author_info":{"display_name":"shababdoo","author_link":"https:\/\/python.garden\/index.php\/author\/shababdoo\/"},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/06\/Selection_1220.png?fit=594%2C91&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":0,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/media\/137"}],"wp:attachment":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}