{"id":73,"date":"2015-05-01T06:36:00","date_gmt":"2015-05-01T10:36:00","guid":{"rendered":"http:\/\/scrolltest.com\/?p=73"},"modified":"2018-12-15T20:45:18","modified_gmt":"2018-12-15T20:45:18","slug":"7-minutes-to-learn-python-programming-right-now","status":"publish","type":"post","link":"https:\/\/scrolltest.com\/7-minutes-to-learn-python-programming-right-now\/","title":{"rendered":"7 minutes to Learn Python Programming Right Now"},"content":{"rendered":"<p>Hi , Its a quick tutorial\u00a0and I have only 7 minutes of your precious time\u00a0So lets start without any further ado.<\/p>\n<h2>Installing Python :<\/h2>\n<ul>\n<li>If you are on Linux or Mac Machine Python is already installed on your system .<\/li>\n<li>On Windows system Simply to the\u00a0https:\/\/www.python.org\/downloads\/ and download the version 2.7.x where x can be anything(My case 9) , see the image below for further reference.<\/li>\n<li>\u00a0 \u00a0 Just add Python to you Path on windows using this <a href=\"https:\/\/docs.python.org\/2\/using\/windows.html\" target=\"_blank\" rel=\"noopener\">Link<\/a><\/li>\n<\/ul>\n<h2>Hello World Saga :<\/h2>\n<pre class=\"lang:default decode:true \">print(\"Hello World\")<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Data Type , Strings with Syntax<\/h2>\n<p>Basic syntax is same any other programming language like Java , The data structures available in python are <span class=\"highlight2\">lists, tuples and dictionaries<\/span>. Sets module provides classes for constructing and manipulating unordered collections of unique elements. Common uses include removing duplicates from a sequence.<\/p>\n<ul>\n<li>Lists are like one-dimensional arrays (but you can also have lists of other lists).\u00a0Tuples are immutable one-dimensional arrays<\/li>\n<li>Dictionaries are associative arrays (a.k.a. hash tables)<\/li>\n<li>Strings \u00a0&#8211; Strings are immutable in python , Below image shows how you can assign a variable with String value and Concatenate it with other data types like Int , Boolean etc.<\/li>\n<\/ul>\n<h2>Loops<\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"lang:python decode:true \">## This is how you take a range in python\r\nmyrange = range(10)\r\nprint(myrange)\r\n\r\nfor item in myrange:\r\nif item in (1,3,5,7,9): ## if item % 2 == 0 for other logic\r\nprint(\"Old Number\")\r\nelse:\r\nprint(\"Even Number\")\r\n\r\nitem = 1\r\nwhile item &lt; 10:\r\nprint(myrange[item])\r\nitem = item+1<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p>[code] Output : range(0, 10) Even Number Old Number Even Number Old Number Even Number Old Number Even Number Old Number Even Number Old Number<br \/>\n1 2 3 4 5 6 7 8 9 [\/code]<\/p><\/blockquote>\n<h2>Functions and Claases<\/h2>\n<p>[python]<\/p>\n<pre class=\"lang:python decode:true \">class myClass:\r\ndef myFunction(self):\r\nprint(\"Hi I am Function\")\r\n\r\ndef myFunctionWithReturn(self):\r\nmyText = \"How are you\"\r\nreturn myText\r\n\r\ndef myFucntionWithArguments(self,number1,number2):\r\nreturn number1+number2\r\n\r\nif __name__== \"__main__\":\r\nmyObj = myClass() ## Creating Object\r\nmyObj.myFunction()\r\nmyValue = myObj.myFucntionWithArguments(1,2)\r\nprint(myValue)<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p>\u00a0Hi I am Function 3<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>Exceptions<\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"lang:python decode:true \">def some_function():\r\ntry:\r\n# Division by zero raises an exception\r\n10 \/ 0\r\nexcept ZeroDivisionError:\r\nprint \"Oops, invalid.\"\r\nelse:\r\n# Exception didn't occur, we're good.\r\npass\r\nfinally:\r\n# This is executed after the code block is run\r\n# and all exceptions have been handled, even\r\n# if a new exception is raised while handling.\r\nprint \"We're done with that.\"<\/pre>\n<p>&gt;&gt;&gt; some_function()<br \/>\nOops, invalid.<br \/>\nWe&#8217;re done with that.<\/p>\n<p>&nbsp;<\/p>\n<h2>File I\/O<\/h2>\n<pre class=\"lang:python decode:true \">f =open(\"myFile.txt\",\"w\")\r\n&gt;&gt;&gt; f.readline()<\/pre>\n<pre class=\"lang:default decode:true \">'This is the first line of the file.n'\r\nor\r\n\r\nfor line in f:\r\nprint line,\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><a href=\"https:\/\/docs.python.org\/2\/tutorial\/inputoutput.html#methods-of-file-objects\" target=\"_blank\" rel=\"noopener\">More IO operations here<\/a><\/strong><\/p>\n<blockquote><p>I hope I was able to give you a quick glimpse of Python in 7 minutes. Please leave comments if you believe there is something that could be improved or added or if there is anything else you would like to see.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Hi , Its a quick tutorial\u00a0and I have only 7 minutes of your precious time\u00a0So lets start without any further ado. Installing Python : If you are on Linux or Mac Machine Python is already installed on your system . On Windows system Simply to the\u00a0https:\/\/www.python.org\/downloads\/ and download the version 2.7.x where x can be&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[5],"tags":[7,10,13,14,17],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-python","tag-7-minutes","tag-hello-world","tag-print","tag-python","tag-training"],"taxonomy_info":{"category":[{"value":5,"label":"Python"}],"post_tag":[{"value":7,"label":"7 minutes"},{"value":10,"label":"Hello World"},{"value":13,"label":"print"},{"value":14,"label":"python"},{"value":17,"label":"training"}]},"featured_image_src_large":false,"author_info":{"display_name":"Promode","author_link":"https:\/\/scrolltest.com\/author\/admin\/"},"comment_info":1,"category_info":[{"term_id":5,"name":"Python","slug":"python","term_group":0,"term_taxonomy_id":5,"taxonomy":"category","description":"","parent":0,"count":29,"filter":"raw","cat_ID":5,"category_count":29,"category_description":"","cat_name":"Python","category_nicename":"python","category_parent":0}],"tag_info":[{"term_id":7,"name":"7 minutes","slug":"7-minutes","term_group":0,"term_taxonomy_id":7,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":10,"name":"Hello World","slug":"hello-world","term_group":0,"term_taxonomy_id":10,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"},{"term_id":13,"name":"print","slug":"print","term_group":0,"term_taxonomy_id":13,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":14,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":14,"taxonomy":"post_tag","description":"","parent":0,"count":20,"filter":"raw"},{"term_id":17,"name":"training","slug":"training","term_group":0,"term_taxonomy_id":17,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}