{"id":2922,"date":"2018-02-22T12:10:17","date_gmt":"2018-02-22T12:10:17","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2922"},"modified":"2018-02-23T08:28:34","modified_gmt":"2018-02-23T08:28:34","slug":"python-2-7-getting-started","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2018\/02\/22\/python-2-7-getting-started\/","title":{"rendered":"Python 2.7 &#8211; Getting Started"},"content":{"rendered":"<h3>WHY PYTHON<\/h3>\n<p>There are lots of languages out there as of 2018 and one question which bothers someone who wants to learn programming is &#8220;which language should I learn?&#8221;. There is no general agreement on this as people would probably recommend one of the following: C, C++, Java, Python. Most universities also stick to pretty much one of these languages or a combination of these. But even among these few, one has to make a start somewhere with one language. So I feel its Python (others may differ). My reasons are given below:<\/p>\n<ul>\n<li>It is a rich and mature language. which is widely used by scientists, academics, colleges and it has a huge repository of libraries and source for for virtually everything from numeric processing to audio programming to databases to websites<\/li>\n<li>It has a gentle learning curve. The syntax is easy to understand and there is very little use of brackets and semi-colon delimiters. The only quirk is the horizontal indenting restriction (more on that in the next sections)<\/li>\n<li>It is available on all major OS &#8211; Windows, Linux, Unix, MacOS to even embedded OS like Raspberry Pi<\/li>\n<li>It lends itself easily to scripting quick tools as well as writing huge applications.<\/li>\n<li>It is a very contemporary and in-demand language. New and exciting areas like AI, machine learning, computer vision, audio processing etc. all have a strong Python usage.<\/li>\n<li>It is a very expressive language i.e you can get a lot done with very little code as compared to other languages<\/li>\n<\/ul>\n<p>The current version of Python is 3.x . However there is a lot of existing software out there which is in 2.x so I am sticking with 2.7 . There are various differences between Python 3 and Python 2 but they are not very major and at a certain stage later on you can easily transition to Python 3 . Python 2.7 official support will end in the year 2020 so still a few years to go .<\/p>\n<h3>INSTALLING PYTHON<\/h3>\n<p>This part is quite simple. Just head over to the official downloads page\u00a0<a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.python.org\/downloads\/<\/a>\u00a0and the website will automatically detect what OS you are on and give you download options for that platform. It will offer you download options for version 3.x and 2.x Make sure to choose the 2.x option.<\/p>\n<p>For MacOS and Windows, you can download installers which then install Python in your system.<\/p>\n<p>For Linux, if you are using a <strong>Debian<\/strong> or a Debian variant like <strong>Ubuntu<\/strong>, the following commands should do the trick<\/p>\n<pre class=\"lang-bsh prettyprint prettyprinted\"><code><span class=\"com\"># refreshing the repositories<\/span><span class=\"pln\">\r\nsudo apt update\r\n<\/span><span class=\"pln\">sudo apt dist<\/span><span class=\"pun\">-<\/span><span class=\"pln\">upgrade\r\n<\/span><span class=\"com\"># installing python 2.7 <\/span><span class=\"pln\">\r\nsudo apt install python2<\/span><span class=\"pun\">.<\/span><span class=\"lit\">7<\/span> python-pip\r\n\r\n<\/code><\/pre>\n<h3><\/h3>\n<p><strong>For Fedora:<\/strong><\/p>\n<pre><span class=\"n\">sudo<\/span> <span class=\"n\">dnf<\/span> <span class=\"n\">upgrade<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">setuptools<\/span> <span class=\"n\">sudo<\/span> <span class=\"n\">dnf<\/span> <span class=\"n\">install<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">pip<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">wheel<\/span><\/pre>\n<p><strong>For CentOS\/RHEL<\/strong><br \/>\nEnable the <a class=\"reference external\" href=\"https:\/\/fedoraproject.org\/wiki\/EPEL\">EPEL repository<\/a> using <a class=\"reference external\" href=\"https:\/\/fedoraproject.org\/wiki\/EPEL#How_can_I_use_these_extra_packages.3F\">these instructions<\/a>. On EPEL 6 and EPEL7, you can install pip :<\/p>\n<pre><span class=\"n\">sudo<\/span> <span class=\"n\">yum<\/span> <span class=\"n\">install<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">pip<\/span><\/pre>\n<p>On EPEL 7 (but not EPEL 6), you can install wheel:<\/p>\n<pre><span class=\"n\">sudo<\/span> <span class=\"n\">yum<\/span> <span class=\"n\">install<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">wheel\r\n\r\n<\/span><\/pre>\n<p><strong>For OpenSUSE<\/strong><\/p>\n<pre><span class=\"n\">sudo<\/span> <span class=\"n\">zypper<\/span> <span class=\"n\">install<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">pip<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">setuptools<\/span> <span class=\"n\">python<\/span><span class=\"o\">-<\/span><span class=\"n\">wheel\r\n\r\n\r\n<\/span><\/pre>\n<h3>EXECUTING PYTHON CODE<\/h3>\n<p>We will be using the command line Python interpreter for all the lessons in the Fundamentals section. Open a command prompt . For Windows users if the Python folder has not been added to the system PATH variable, you will have to navigate to the Python installation folder eg. c:\\python2.7 and then run the Python interpreter from there.<\/p>\n<p>So lets load the Python interpreter. Just type <strong>python\u00a0<\/strong>and press Enter<\/p>\n<p>You should see something similar to this:<\/p>\n<p><a href=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1.tiff\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-2967\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1.tiff\" alt=\"\" width=\"1\" height=\"1\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-2968\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1-620x102.jpg\" alt=\"\" width=\"620\" height=\"102\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1-620x102.jpg 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1-300x49.jpg 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2018\/02\/python1.jpg 632w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>For now just type in<\/p>\n<p><em>print &#8220;Hello World&#8221;<\/em><\/p>\n<p>and press Enter<\/p>\n<p>That&#8217;s it. You have just written your first Python statement. To exit the interpreter type<\/p>\n<p><em>quit()<\/em><\/p>\n<p>In the next post, we will start with understanding <a href=\"https:\/\/truelogic.org\/wordpress\/2018\/02\/23\/python-2-7-fundamentals-primitive-data-types-variables\/\">Primitive Data Types &amp; Variables<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>WHY PYTHON There are lots of languages out there as of 2018 and one question which bothers someone who wants to learn programming is &#8220;which <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2018\/02\/22\/python-2-7-getting-started\/\" title=\"Python 2.7 &#8211; Getting Started\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2107,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[297],"tags":[],"class_list":["post-2922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=2922"}],"version-history":[{"count":9,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2922\/revisions"}],"predecessor-version":[{"id":2989,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2922\/revisions\/2989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2107"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=2922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}