{"id":2203,"date":"2020-03-18T16:04:40","date_gmt":"2020-03-18T16:04:40","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=2203"},"modified":"2020-04-07T18:28:53","modified_gmt":"2020-04-07T12:58:53","slug":"write-first-python-program-hello-world","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/write-first-python-program-hello-world\/","title":{"rendered":"Write your first python Program | Hello World"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In the previous tutorial, we had created a project with the name\u00a0 \u201cHelloWorld\u201d. Now we learn how to write the first Python Program<\/span><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-2204\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_35.png\" alt=\"\" width=\"757\" height=\"558\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_35.png 803w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_35-300x222.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_35-768x567.png 768w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/p>\n<h3><b>Step 1: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Click on the file on the top left of the PyCharm editor and select new as shown in the editor below.\u00a0<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2206\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_36.png\" alt=\"\" width=\"437\" height=\"679\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_36.png 472w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_36-193x300.png 193w\" sizes=\"(max-width: 437px) 100vw, 437px\" \/><\/p>\n<h3><b>Step 2: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Then select \u201cPython file\u201d as shown below.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2207\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_37.png\" alt=\"\" width=\"549\" height=\"542\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_37.png 604w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_37-300x296.png 300w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/p>\n<h3><b>Step 3: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">write the name of the file \u201cHelloWorld\u201d and press enter.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2208\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_38.png\" alt=\"\" width=\"718\" height=\"458\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_38.png 799w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_38-300x191.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_38-768x490.png 768w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/p>\n<h3><b>Step 4: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Now you have the space to write your first program. Write \u201cprint(\u201chello world\u201d)\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2209\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_39.png\" alt=\"\" width=\"716\" height=\"383\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_39.png 793w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_39-300x160.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_39-768x411.png 768w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/p>\n<h3><b>Step 5: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Right-click on the white space and menu will be shown.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0Then select \u201cRun \u2018HelloWorld\u2019\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2210\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_40.png\" alt=\"\" width=\"723\" height=\"406\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_40.png 804w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_40-300x168.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_40-768x431.png 768w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_40-390x220.png 390w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<h3><b>Step 6: <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Below a terminal will open and the output of the program will be shown.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2211\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_41.png\" alt=\"\" width=\"731\" height=\"381\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_41.png 798w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_41-300x156.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_41-768x400.png 768w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_41-780x405.png 780w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p>\n<p><b>Congratulations you have successfully written your first program.<\/b><\/p>\n<h2><b>Rectangle Example<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Now let us see how we can simply draw a rectangle using <\/span><b>print() <\/b><span style=\"font-weight: 400;\">statement. Python executes the code line by line. We are going to use \u2018*\u2019 to print the rectangle. Simply write the program as shown below.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2212\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_42.png\" alt=\"\" width=\"527\" height=\"267\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_42.png 643w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_42-300x152.png 300w\" sizes=\"(max-width: 527px) 100vw, 527px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Then repeat <\/span><b>step 5<\/b><span style=\"font-weight: 400;\"> to run the program.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You have successfully drawn the rectangle.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2213\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_43.png\" alt=\"\" width=\"697\" height=\"371\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_43.png 797w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_43-300x160.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_43-768x409.png 768w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In the upcoming tutorials, we will see how we can reduce the repetitions of writing the same lines of code.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>How to print blank lines<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Python allows three ways to print blank lines.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">print()<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">print(\u201c \u201d)<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">print(\u201cwrite backward slash n at end of text\\n\u201d)<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Let us try all three ways to print blank lines.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 1 and 2 have no blank space between them.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 3 and 5 prints a blank space.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 6 uses \u201c\\n\u201d at the end to print the blank space.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2214\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_44.png\" alt=\"\" width=\"689\" height=\"373\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_44.png 791w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_44-300x162.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_44-768x416.png 768w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/><\/p>\n<h2><b>Use of end in print()<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">As the print is a function, we can pass an \u201cend\u201d optional parameter. If you don\u2019t understand parameters don\u2019t worry, you will understand in the upcoming function tutorials.\u00a0 \u201cend\u201d is used to tell the print statement how we want to end the print line. In the previous examples, we used the default end parameter which automatically end the line.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s understand with an example.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Line 1 and 2 are simple print statements as we use print statement previously.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 3 prints a blank line.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 4 uses end=\u201d \u201cmeans \u201cend this print line with a blank whitespace not with blank line\u201d.<br \/>\n<\/span><span style=\"font-weight: 400;\">Line 7 uses end=\u201d&#8212;&#8221; means \u201cend this print line with &#8212;\u201d.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">See the difference in the output.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2215\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_45.png\" alt=\"\" width=\"701\" height=\"374\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_45.png 787w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_45-300x160.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2020\/03\/Screenshot_45-768x410.png 768w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous tutorial, we had created a project with the name\u00a0 \u201cHelloWorld\u201d. Now we learn how to write the first Python Program Step 1: Click on the file on the top left of the PyCharm editor and select new as shown in the editor below.\u00a0 Step 2: Then select \u201cPython file\u201d as shown below. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2411,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[342],"tags":[438,437,433,436],"class_list":["post-2203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-helloworld","tag-program","tag-python","tag-write-first-python-program"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=2203"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/2203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/2411"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=2203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=2203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=2203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}