{"id":12,"date":"2023-06-12T17:14:33","date_gmt":"2023-06-12T17:14:33","guid":{"rendered":"https:\/\/farrukhnaveed.co\/blog\/?p=12"},"modified":"2023-09-13T22:53:02","modified_gmt":"2023-09-13T17:23:02","slug":"everything-you-need-to-learn-about-python","status":"publish","type":"post","link":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/","title":{"rendered":"Everything you need to learn about Python"},"content":{"rendered":"\n<p id=\"3c2b\">This article aims to outline all of the key points of the Python programming language. My target is to keep the information&nbsp;<strong>short, relevant, and focus<\/strong>&nbsp;on the most important topics which are absolutely required to be understood.<\/p>\n\n\n\n<p id=\"7b88\"><strong>After reading this blog, you will be able to use any Python library or implement your own Python packages.<\/strong><\/p>\n\n\n\n<p id=\"bfd7\"><em>You are not expected to have any prior programming knowledge and it will be very quick to grasp all of the required concepts.<\/em><\/p>\n\n\n\n<p id=\"2960\"><strong>I will also highlight top discussion questions that people usually query regarding Python programming language.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"a749\">Lets build the knowledge gradually and by the end of the article, you will have a thorough understanding of Python.<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:803\/1*V3RT5yJmh6ihakR7jhg2dw.png\" alt=\"\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"0f5a\">This article contains 25 key topics. Let\u2019s Start.<\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"f637\">1. Introducing Python<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5a1b\">What Is Python?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Interpreted&nbsp;<strong>high-level object-oriented dynamically-typed scripting<\/strong>&nbsp;language.<\/li>\n\n\n\n<li>As a result,&nbsp;<strong>run time errors<\/strong>&nbsp;are usually encountered.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7a91\">Why Python?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python is the most popular language due to the fact that it\u2019s easier to code and understand it.<\/li>\n\n\n\n<li>Python is an object-oriented programming language and can be used to write functional code too.<\/li>\n\n\n\n<li>It is a suitable language that bridges the gaps between business and developers.<\/li>\n\n\n\n<li>Subsequently, it takes less time to bring a Python program to market compared to other languages such as C#\/Java.<\/li>\n\n\n\n<li>Additionally, there are a large number of python machine learning and analytical packages.<\/li>\n\n\n\n<li>A large number of communities and books are available to support Python developers.<\/li>\n\n\n\n<li>Nearly all types of applications, ranging from forecasting analytical to UI, can be implemented in Python.<\/li>\n\n\n\n<li>There is no need to declare variable types. Thus it is quicker to implement a Python application.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dd97\">Why Not Python?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python is slower than C++, C#, Java. This is due to the lack of Just In Time optimisers in Python.<\/li>\n\n\n\n<li>Python syntactical white-space constraint makes it slightly difficult to implement for new coders.<\/li>\n\n\n\n<li>Python does not offer advanced statistical features as R does.<\/li>\n\n\n\n<li>Python is not suitable for low-level systems and hardware interaction.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"64da\">How Does Python Work?<\/h2>\n\n\n\n<p id=\"30ec\">This image illustrates how python runs on our machines:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:604\/1*kDCG2OHPSUT8SBM8n9UPkQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"ad45\">The key here is the Interpreter that is responsible for translating high-level Python language to low-level machine language.<\/p>\n\n\n\n<p id=\"5aef\">The way Python works is as follows:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A Python virtual machine is created where the packages (libraries) are installed. Think of a virtual machine as a container.<\/li>\n\n\n\n<li>The python code is then written in .py files<\/li>\n\n\n\n<li>CPython compiles the Python code to bytecode. This bytecode is for the Python virtual machine.<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"ac22\"><em>Now, this virtual machine is machine-dependent but the Python code isn\u2019t.<\/em><\/p>\n<\/blockquote>\n\n\n\n<p id=\"5fe7\">4. When you want to execute the bytecode then the code will be interpreted at runtime. The code will then be translated from the bytecode into the machine code. The bytecode is not dependent on the machine on which you are running the code. This makes Python machine-independent.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"ab7e\"><em>Python byte code is Python virtual machine-dependent and this makes Python machine-independent.<\/em><\/p>\n<\/blockquote>\n\n\n\n<p id=\"3017\">The point to note is that we can write Python code in one OS, copy it to another OS and simply run it.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2b21\">2. Variables \u2014 Object Types And Scope<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables store information that can be used and\/or changed in your program. This information can be an integer, text, collection, etc.<\/li>\n\n\n\n<li>Variables are used to hold user inputs, local states of your program, etc.<\/li>\n\n\n\n<li>Variables have a&nbsp;<strong>name&nbsp;<\/strong>so&nbsp;that&nbsp;they&nbsp;can&nbsp;be&nbsp;referenced in the code.<\/li>\n\n\n\n<li>The fundamental concept to understand is that everything is an object in Python.<\/li>\n<\/ul>\n\n\n\n<p id=\"61a5\"><strong>Python supports numbers, strings, sets, lists, tuples, and dictionaries. These are the standard data types. I will explain each of them in detail.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b491\">Declare And Assign Value To Variable<\/h2>\n\n\n\n<p id=\"1aee\">Assignment sets a value to a variable.<\/p>\n\n\n\n<p id=\"fa25\">To assign variable a value, use the equals sign (=)<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"myFirstVariable = 1\nmySecondVariable = 2\nmyFirstVariable = &quot;Hello You&quot;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">myFirstVariable <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">mySecondVariable <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">myFirstVariable <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Hello You<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Assigning a value is known as&nbsp;<strong>binding&nbsp;<\/strong>in Python. In the example above, we have assigned the value of 1 to myFirstVariable.<\/li>\n<\/ul>\n\n\n\n<p id=\"df36\"><em>Note how I assigned an integer value of 1 and then a string value of \u201cHello You\u201d to the same myFirstVariable variable.&nbsp;<\/em><strong><em>This is possible due to the fact that the data types are dynamically typed in python.<\/em><\/strong><\/p>\n\n\n\n<p id=\"4d77\">This is why Python is known as a dynamically typed programming language.<\/p>\n\n\n\n<p id=\"7cc4\">If you want to assign the same value to more than one variables then you can use the chained assignment:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"myFirstVariable = mySecondVariable = 1\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">myFirstVariable <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> mySecondVariable <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a2be\">Numeric<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Integers, decimals, floats are supported.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"value = 1 #integer\nvalue = 1.2 #float with a floating point\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">value <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#integer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">value <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1.2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#float with a floating point<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Longs are also supported. They have a suffix of L e.g. 9999999999999L<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a4bd\">Strings<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Textual information. Strings are sequence of letters.<\/li>\n\n\n\n<li>A string is an array of characters<\/li>\n\n\n\n<li>A string value is enclosed in quotation marks: single, double or triple quotes.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"name = 'farhad'\nname = &quot;farhad&quot;\nname = &quot;&quot;&quot;farhad&quot;&quot;&quot;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">name <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">farhad<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">name <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">farhad<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">name <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;&quot;&quot;<\/span><span style=\"color: #A3BE8C\">farhad<\/span><span style=\"color: #ECEFF4\">&quot;&quot;&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Strings are immutable. Once they are created, they cannot be changed e.g.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = 'me' #Updating it will fail:\na[1]='y' #It will throw a Type Error\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">me<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#Updating it will fail:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">a<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">y<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#It will throw a Type Error<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When string variables are assigned a new value then internally, Python creates a new object to store the value.<\/li>\n<\/ul>\n\n\n\n<p id=\"79ed\">Therefore a reference\/pointer to an object is created. This pointer is then assigned to the variable and as a result, the variable can be used.<\/p>\n\n\n\n<p id=\"3227\">We can also assign one variable to another variable. All it does is that a new pointer is created which points to the same object:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = 1 #new object is created and 1 is stored there, new pointer is created, the pointer connects a to 1\nb = a #new object is not created, new pointer is created that connects b to 1\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#new object is created and 1 is stored there, new pointer is created, the pointer connects a to 1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> a <\/span><span style=\"color: #616E88\">#new object is not created, new pointer is created that connects b to 1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dfd1\">Variables can have local or global scope.<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c346\">Local Scope<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables declared within a function, as an example, can only exist within the block.<\/li>\n\n\n\n<li>Once the block exists, the variables also become inaccessible.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"def some_funcion():\n  TestMode = False\nprint(TestMode) &lt;- Breaks as the variable doesn't exist outside\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">some_funcion<\/span><span style=\"color: #ECEFF4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  TestMode <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">TestMode<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;-<\/span><span style=\"color: #D8DEE9FF\"> Breaks <\/span><span style=\"color: #81A1C1\">as<\/span><span style=\"color: #D8DEE9FF\"> the variable doesn<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">t exist outside<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"aba2\">In Python, if-else and for\/while loop block doesn\u2019t create any local scope.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"for i in range(1, 11):\n    test_scope = &quot;variable inside for loop&quot;\n    print(test_scope)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">range<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">11<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    test_scope <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">variable inside for loop<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">test_scope<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"fd30\">Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable inside for loop<\/pre>\n\n\n\n<p id=\"7dee\">With if-else block<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"is_python_awesome = True\nif is_python_awesome:\n    test_scope = &quot;Python is awesome&quot;\nprint(test_scope)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">is_python_awesome <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> is_python_awesome<\/span><span style=\"color: #ECEFF4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    test_scope <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Python is awesome<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">test_scope<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"f914\">Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python is awesome<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"69aa\">Global Scope<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables that can be accessed from any function have a global scope. They exist in the __main__ frame.<\/li>\n\n\n\n<li>You can declare a global variable outside of functions. It\u2019s important to note that to assign a global variable a new value, you will have to use the \u201c<em>global<\/em>\u201d keyword:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"TestMode = True\ndef some_function():\n  global TestMode\n  TestMode = False\n  \nsome_function()\nprint(TestMode) &lt;--Returns False\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">TestMode <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">some_function<\/span><span style=\"color: #ECEFF4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #81A1C1\">global<\/span><span style=\"color: #D8DEE9FF\"> TestMode<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  TestMode <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">some_function<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">TestMode<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9\">--<\/span><span style=\"color: #D8DEE9FF\">Returns <\/span><span style=\"color: #81A1C1\">False<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"a2f9\"><em>Removing the line \u201cglobal TestMode\u201d will only set the variable to False within the some_function() function.<\/em><\/p>\n\n\n\n<p id=\"ff1b\"><strong>Note: Although I will write more on the concept of modules later, but if you want to share a global variable across a number of modules then you can create a shared module file e.g. configuration.py and locate your variable there. Finally, import the shared module in your consumer modules.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c358\">Finding Variable Type<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to find the type of a variable, you can implement:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"type('farhad')\n--&gt; Returns &lt;type 'str'&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">type<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">farhad<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">--<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> Returns <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #88C0D0\">type<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">str<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"56d6\">Comma In Integer Variables<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Commas are treated as a sequence of variables e.g.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">9,8,7 are three numeric variables<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"5a71\">3. Operations<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allows us to perform computation on variables<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3dd2\">Numeric Operations<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python supports basic&nbsp;<strong>*, \/, +, &#8211;<\/strong><\/li>\n\n\n\n<li>Python also supports floor division<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"1\/\/3  #returns 0\n1\/3 #returns 0.333 \" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #81A1C1\">\/\/<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\">#returns 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#returns 0.333 <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Note: the return type of division is always&nbsp;<strong>float<\/strong>&nbsp;as shown below:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = 10\/5\nprint(type(a)) #prints float\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">10<\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #B48EAD\">5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">type<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">a<\/span><span style=\"color: #ECEFF4\">))<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#prints float<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Additionally, python supports exponentiation via ** operator:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"2**3 = 2 * 2 * 2 = 8\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #81A1C1\">**<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">8<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python supports Modulus (remainder) operator too:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"7%2 = 1\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B48EAD\">7<\/span><span style=\"color: #81A1C1\">%<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"6792\">There is also a divmod in-built method. It returns the divider and modulus:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"print(divmod(10,3)) #it will print 3 and 1 as 3*3 = 9 +1 = 10\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">divmod<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #B48EAD\">10<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">))<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#it will print 3 and 1 as 3*3 = 9 +1 = 10<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fa0a\">String Operations<\/h2>\n\n\n\n<p id=\"70a4\"><strong>Concat Strings:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'A' + 'B' = 'AB'\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">A<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">B<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">AB<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"07b1\">Remember string is an immutable data type, therefore, concatenating strings creates a new string object.<\/p>\n\n\n\n<p id=\"82e5\"><strong>Repeat String:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'A'*3 #will repeat A three times:  AAA\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">A<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#will repeat A three times:  AAA<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"102c\"><strong>Slicing:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"y = 'Abc'\ny[:2] = ab\ny[1:] = bc\ny[:-2] = a\ny[-2:] = bc\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">y <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Abc<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[:<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> ab<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">:]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> bc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[:<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">:]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> bc<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"d05a\"><strong>Reversing:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"x = 'abc'\nx = x[::-1]\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">x <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">abc<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">x <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> x<\/span><span style=\"color: #ECEFF4\">[::<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"35ed\"><strong>Negative Index:<\/strong><\/p>\n\n\n\n<p id=\"4a60\">If you want to start from the last character then use negative index.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"y = 'abc'\nprint(y[:-1]) # will return ab\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">y <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">abc<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[:<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">])<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\"># will return ab<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"1b38\">It is also used to remove any new line carriages\/spaces.<\/p>\n\n\n\n<p id=\"f649\">Each element in an array gets two indexes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>From left to right, the index starts at 0 and increments by 1<\/li>\n\n\n\n<li>From right to left, the index starts at -1 and decrements by 1<\/li>\n\n\n\n<li>Therefore, if we do y[0] and y[-len(y)] then both will return the same value: \u2018a\u2019<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"y = 'abc'\nprint(y[0])\nprint(y[-len(y)])\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">y <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">abc<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #88C0D0\">len<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">y<\/span><span style=\"color: #ECEFF4\">)])<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"73de\"><strong>Finding Index<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"name = 'farhad'\nindex = name.find('r') #returns 2name = 'farhad'\nindex = name.find('a', 2) # finds index of second a#returns 4\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">name <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">farhad<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">index <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> name<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">find<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">r<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">#returns 2name = &#39;farhad&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">index <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> name<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">find<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">a<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\"># finds index of second a#returns 4<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"e8f5\"><strong>For Regex, use:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>split(): splits a string into a list via regex<\/li>\n\n\n\n<li>sub(): replaces matched string via regex<\/li>\n\n\n\n<li>subn(): replaces matched string via regex and returns number of replacements<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"f376\"><strong>Casting<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>str(x): To string<\/li>\n\n\n\n<li>int(x): To integer<\/li>\n\n\n\n<li>float(x): To floats<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7de7\">Set Operations<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A set is an unordered data collection without any duplicates. We can define a set variable as:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"set = {9,1,-1,5,2,8,3, 8}\nprint(set)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">set<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">9<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">8<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">8<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">set<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"d1ea\">This will print: {1, 2, 3, 5, 8, 9, -1}<\/p>\n\n\n\n<p id=\"0d02\">Note duplicates are removed.<\/p>\n\n\n\n<p id=\"b600\">Set has&nbsp;<em>a item in set, len(set)<\/em>&nbsp;and&nbsp;<em>for item in set&nbsp;<\/em>operations. However it does not support indexing, slicing like lists.<\/p>\n\n\n\n<p id=\"5420\">Some of the most important set operations are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>set.add(item) \u2014 adds item to the set<\/li>\n\n\n\n<li>set.remove(item) \u2014 removes item from the set and raises error if it is not present<\/li>\n\n\n\n<li>set.discard(item) \u2014 removes item from the set if it is present<\/li>\n\n\n\n<li>set.pop() \u2014 returns any item from the set, raises KeyError if the set is empty<\/li>\n\n\n\n<li>set.clear() clears the set<\/li>\n<\/ul>\n\n\n\n<p id=\"b613\"><strong>Intersect Sets<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To get what\u2019s common in two sets<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = {1,2,3}\nb = {3,4,5}\nc = a.intersection(b)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">4<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">c <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> a<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">intersection<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">b<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"94e9\"><strong>Difference In Sets<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To retrieve the difference between two sets:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = {1,2,3}\nb = {3,4,5}\nc = a.difference(b)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">4<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">c <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> a<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">difference<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">b<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p id=\"195f\"><strong>Union Of Collections<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To get a distinct combined set of two sets<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"a = {1,2,3}\nb = {3,4,5}\nc = a.union(b)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">a <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">4<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">c <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> a<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">union<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">b<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c93a\">Ternary Operator<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Used to write conditional statements in a single line.<\/li>\n<\/ul>\n\n\n\n<p id=\"9f93\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<p id=\"edb7\"><strong><em>[If True] if [Expression] Else [If False]<\/em><\/strong><\/p>\n\n\n\n<p id=\"7ef9\">For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Received = True if x == 'Yes' else False\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">Received <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">True<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> x <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Yes<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">else<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">False<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"c1a9\">4. Comments<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"274f\">Single Line Comments<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# This is a single line comment\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\"># This is a single line comment<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7819\">Multiple Line Comments<\/h2>\n\n\n\n<p id=\"84ca\">One can use:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"```this is a multi\nline\ncomment```\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9\">```this <\/span><span style=\"color: #81A1C1\">is<\/span><span style=\"color: #D8DEE9\"> a multi<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">line<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">comment<\/span><span style=\"color: #D8DEE9\">```<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3197\">5. Expressions<\/h1>\n\n\n\n<p id=\"35fb\">Expressions can perform boolean operations such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Equality: ==<\/li>\n\n\n\n<li>Not Equal: !=<\/li>\n\n\n\n<li>Greater: &gt;<\/li>\n\n\n\n<li>Less: &lt;<\/li>\n\n\n\n<li>Greater Or Equal &gt;=<\/li>\n\n\n\n<li>Less Or Equal &lt;=<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6b12\">6. Pickling<\/h1>\n\n\n\n<p id=\"4730\">Converting an object into a string and dumping the string into a binary file is known as pickling. The reverse is known as unpickling.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7614\">7. Functions<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Functions are sequence of statements that you can execute in your code. If you see repetition in your code then create a reusable function and use it in your program.<\/li>\n\n\n\n<li>Functions can also reference other functions.<\/li>\n\n\n\n<li>Functions eliminate repetition in your code. They make it easier to debug and find issues.<\/li>\n\n\n\n<li>Finally, functions enable code to be understandable and easier to manage.<\/li>\n\n\n\n<li>In short, functions allow us to split a large application into smaller chunks.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"74bf\">Define New Function<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"def my_new_function():\n  print('this is my new function')\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">my_new_function<\/span><span style=\"color: #ECEFF4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">this is my new function<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e5ba\">Calling Function<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"my_new_function()\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">my_new_function<\/span><span style=\"color: #ECEFF4\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ebc3\">Finding Length Of String<\/h2>\n\n\n\n<p id=\"b3b3\">Call the len(x) function<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"len('hello') # prints 5\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">len<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">hello<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\"># prints 5<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"05c9\">Arguments<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arguments can be added to a function to make the functions generic.<\/li>\n\n\n\n<li>This exercise is known as generalization.<\/li>\n\n\n\n<li>You can pass in variables to a method:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">def my_new_function(my_value):<br>  print('this is my new function with ' + my_value)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Optional arguments:<\/strong><\/li>\n<\/ul>\n\n\n\n<p id=\"bcef\">We can pass in optional arguments by providing a default value to an argument:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def my_new_function(my_value='hello'):<br>  print(my_value)#Calling<br>my_new_function() =&gt; prints hello<br>my_new_function('test') =&gt; prints test<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>*arguments:<\/strong><\/li>\n<\/ul>\n\n\n\n<p id=\"702b\">If your function can take in any number of arguments then add a * in front of the parameter name:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def myfunc(*arguments):<br>  return amyfunc(a)<br>myfunc(a,b)<br>myfunc(a,b,c)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>**arguments:<\/strong><\/li>\n<\/ul>\n\n\n\n<p id=\"36a2\">It allows you to pass a varying number of keyword arguments to a function.<\/p>\n\n\n\n<p id=\"c2d8\">You can also pass in dictionary values as keyword arguments.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def test(*args, **kargs):<br>    print(args)<br>    print(kargs)<br>    print(args[0])<br>print(kargs.get('a'))<br>alpha = 'alpha'<br>beta = 'beta'<br>test(alpha, beta, a=1, b=2)<\/pre>\n\n\n\n<p id=\"608f\">This will print:<\/p>\n\n\n\n<p id=\"5028\">(3, 1)<br>(\u2018alpha\u2019, \u2018beta\u2019)<br>{\u2018a\u2019: 1, \u2018b\u2019: 2}<br>alpha<br>1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0170\">Return<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Functions can return values such as:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">def my_function(input):<br>  return input + 2<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If a function is required to return multiple values then it\u2019s suitable to return a tuple (comma separated values). I will explain tuples later on:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">resultA, resultB = get_result()get_result() can return ('a', 1) which is a tuple<\/pre>\n\n\n\n<p id=\"a7b2\"><strong>Lambda<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Single expression anonymous function.<\/li>\n\n\n\n<li>It is an inline function.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_lambda = lambda x,y,z : x - 100 + y - zmy_lambda(100, 100, 100) # returns 0<\/pre>\n\n\n\n<p id=\"5940\"><strong>Syntax<\/strong>:<\/p>\n\n\n\n<p id=\"4264\"><em>variable = lambda arguments: expression<\/em><\/p>\n\n\n\n<p id=\"03c2\"><em>Lambda functions can be passed as arguments to other functions.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c7b4\">Object Identity<\/h2>\n\n\n\n<p id=\"a170\">I will attempt to explain the important subject of Object Identity now.<\/p>\n\n\n\n<p id=\"782c\">Whenever we create an object in Python such as a variable, function, etc, the underlying Python interpreter creates a number that uniquely identifies that object. Some of the objects are created up-front.<\/p>\n\n\n\n<p id=\"1db0\">When an object is not referenced anymore in the code then it is removed and its identity number can be used by other variables.<\/p>\n\n\n\n<p id=\"a66a\"><strong>dir() and help()<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>dir() -displays defined symbols<\/li>\n\n\n\n<li>help() \u2014 displays documentation<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2a4e\">Let\u2019s understand it in detail:<\/h2>\n\n\n\n<p id=\"aa0a\">Consider the code below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var_one = 123<br>def func_one(var_one):<br>    var_one = 234<br>    var_three = 'abc'var_two = 456<br>print(dir())<\/pre>\n\n\n\n<p id=\"357b\">var_one and var_two are the two variables that are defined in the code above. Along with the variables, a function named func_one is also defined. An important note to keep in mind is that everything is an object in Python, including a function.<\/p>\n\n\n\n<p id=\"e5ab\">Within the function, we have assigned the value of 234 to var_one and created a new variable named var_three and assigned it a value of \u2018abc\u2019.<\/p>\n\n\n\n<p id=\"cc3a\"><strong>Now, let\u2019s understand the code with the help of dir() and id()<\/strong><\/p>\n\n\n\n<p id=\"fdef\">The above code and its variables and functions will be loaded in the Global frame. The global frame will hold all of the objects that the other frames require. As an example, there are many built-in methods loaded in Python that are available to all of the frames. These are the function frames.<\/p>\n\n\n\n<p id=\"ec40\">Running the above code will print:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>[\u2018__annotations__\u2019, \u2018__builtins__\u2019, \u2018__cached__\u2019, \u2018__doc__\u2019, \u2018__file__\u2019, \u2018__loader__\u2019, \u2018__name__\u2019, \u2018__package__\u2019, \u2018__spec__\u2019, <\/em><strong><em>\u2018func_one\u2019, \u2018var_one\u2019, \u2018var_two\u2019<\/em><\/strong><em>]<\/em><\/pre>\n\n\n\n<p id=\"8bde\">The variables that are prefixed with __ are known as the special variables.<\/p>\n\n\n\n<p id=\"2338\">Notice that the var_three is not available yet. Let\u2019s execute func_one(var_one) and then assess the dir():<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var_one = 123<br>def func_one(var_one):<br>    var_one = 234<br>    var_three = 'abc'<br><br>var_two = 456<br>func_one(var_one)<br>print(dir())<\/pre>\n\n\n\n<p id=\"eca5\">We will again see the same list:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'func_one', 'var_one', 'var_two']<\/pre>\n\n\n\n<p id=\"bf99\">This means that the variables within the func_one are only within the func_one. When func_one is executed then a Frame is created. Python is top-down therefore it always executes the lines from top to the bottom.<\/p>\n\n\n\n<p id=\"1e31\">The function frame can reference the variables in the global frame but any other function frame cannot reference the same variables that are created within itself. As an instance, if I create a new function func_two that tries to print var_three then it will fail:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var_one = 123<br>def func_one(var_one):<br>    var_one = 234<br>    var_three = 'abc'<br><br>var_two = 456<br><br><br>def func_two():<br>    print(var_three)<br><br>func_one(var_one)<br>func_two()<br>print(dir())<\/pre>\n\n\n\n<p id=\"6f59\">We get an error that&nbsp;<strong>NameError: name \u2018var_three\u2019 is not defined<\/strong><\/p>\n\n\n\n<p id=\"7b42\"><strong>What if we create a new variable inside func_two() and then print the dir()?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var_one = 123<br>def func_one(var_one):<br>    var_one = 234<br>    var_three = 'abc'<br><br>var_two = 456<br><br><br>def func_two():<br>    var_four = 123<br>    print(dir())func_two()<\/pre>\n\n\n\n<p id=\"5a69\">This will print var_four as it is local to func_two.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7a70\">How does Assignment work In Python?<\/h2>\n\n\n\n<p id=\"7370\">This is by far one of the most important concepts to understand in Python. Python has an id() function.<\/p>\n\n\n\n<p id=\"e52e\">When an object (function, variable, etc.) is created, CPython allocates it an address in memory. The id() function returns the \u201cidentity\u201d of an object. It is essentially a unique integer.<\/p>\n\n\n\n<p id=\"7742\">As an instance, let\u2019s create four variables and assign them values:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable1 = 1<br>variable2 = \"abc\"<br>variable3 = (1,2)<br>variable4 = ['a',1]#Print their Ids<br>print('Variable1: ', id(variable1))<br>print('Variable2: ', id(variable2))<br>print('Variable3: ', id(variable3))<br>print('Variable4: ', id(variable4))<\/pre>\n\n\n\n<p id=\"2fab\">The ids will be printed as follows:<\/p>\n\n\n\n<p id=\"91f9\">Variable1: 1747938368<br>Variable2: 152386423976<br>Variable3: 152382712136<br>Variable4: 152382633160<\/p>\n\n\n\n<p id=\"ce37\">Each variable has been assigned a new integer value.<\/p>\n\n\n\n<p id=\"d240\">The first assumption is that whenever we use the assignment \u201c=\u201d then Python creates a new memory address to store the variable. Is it 100% true, not really!<\/p>\n\n\n\n<p id=\"dd13\">I am going to create two variables and assign them to the existing variables.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable5 = variable1<br>variable6 = variable4<br><br>print('Variable1: ', id(variable1))<br>print('Variable4: ', id(variable4))<br>print('Variable5: ', id(variable5))<br>print('Variable6: ', id(variable6))<\/pre>\n\n\n\n<p id=\"a7ed\">Python printed:<\/p>\n\n\n\n<p id=\"e6f3\">Variable1:&nbsp;<strong>1747938368<\/strong><br>Variable4: 819035469000<br>Variable5:&nbsp;<strong>1747938368<\/strong><br>Variable6: 819035469000<\/p>\n\n\n\n<p id=\"4efe\"><em>Notice that Python did not create new memory addresses for the two variables. This time, it pointed both of the variables to the same memory location.<\/em><\/p>\n\n\n\n<p id=\"f4c7\">Let\u2019s set a new value to the variable1. Remember 2 is an integer and integer is an immutable data type.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print('Variable1: ', id(variable1))<br>variable1 = 2<br>print('Variable1: ', id(variable1))<\/pre>\n\n\n\n<p id=\"47f5\">This will print:<\/p>\n\n\n\n<p id=\"8691\"><em>Variable1: 1747938368<br>Variable1: 1747938400<\/em><\/p>\n\n\n\n<p id=\"2ab2\"><strong>It means whenever we use the = and assign a new value to a variable that is not a variable then internally a new memory address is created to store the variable. Let\u2019s see if it holds!<\/strong><\/p>\n\n\n\n<p id=\"af6a\">What happens when the value is a mutable data type?<\/p>\n\n\n\n<p id=\"a9dd\">variable6 is a list. Let\u2019s append an item to it and print its memory address:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print('Variable6: ', id(variable6))<br>variable6.append('new')<br>print('Variable6: ', id(variable6))<\/pre>\n\n\n\n<p id=\"6e9a\">Note that the memory address remained the same for the variable as it is a mutable data type and we simply updated its elements.<\/p>\n\n\n\n<p id=\"8620\">Variable6: 678181106888<br>Variable6: 678181106888<\/p>\n\n\n\n<p id=\"602e\">Let\u2019s create a function and pass a variable to it. If we set the value of the variable inside the function, what will it do internally? let\u2019s assess<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def update_variable(variable_to_update):<br>    print(id(variable_to_update))<br>update_variable(variable6)<br>print('Variable6: ', id(variable6))<\/pre>\n\n\n\n<p id=\"423e\">We get:<\/p>\n\n\n\n<p id=\"df09\">678181106888<br>Variable6: 678181106888<\/p>\n\n\n\n<p id=\"3bdc\">Notice that the id of variable_to_update points to the id of the variable 6.<\/p>\n\n\n\n<p id=\"6676\">This means that if we update the variable_to_update in a function and if variable_to_update is a mutable data type then we\u2019ll update variable6.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable6 = ['new']<br>print('Variable6: ', variable6)<br><br>def update_variable(variable_to_update):<br>    variable_to_update.append('inside')update_variable(variable6)<br>print('Variable6: ', variable6)<\/pre>\n\n\n\n<p id=\"0c45\">This printed:<\/p>\n\n\n\n<p id=\"9503\">Variable6: [\u2018new\u2019]<br>Variable6: [\u2018new\u2019, \u2018inside\u2019]<\/p>\n\n\n\n<p id=\"d10d\">It shows us that the same object is updated within the function as it was expected by both having the same ID.<\/p>\n\n\n\n<p id=\"0b86\">If we assign a new value to a variable, regardless of if it\u2019s immutable and mutable data type then the change will be lost once we come out of the function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print('Variable6: ', variable6)<br><br>def update_variable(variable_to_update):<br>    print(id(variable_to_update))<br>    variable_to_update = ['inside']update_variable(variable6)<br>print('Variable6: ', variable6)<\/pre>\n\n\n\n<p id=\"cd8f\">Variable6: [\u2018new\u2019]<br>344115201992<br>Variable6: [\u2018new\u2019]<\/p>\n\n\n\n<p id=\"bfa8\"><strong>Now an interesting scenario: Python doesn\u2019t always create a new memory address for all new variables.<\/strong><\/p>\n\n\n\n<p id=\"b63b\">Finally, what if we assign two different variables a string value such as \u2018a\u2019. Will it create two memory addresses?<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable_nine = \"a\"<br>variable_ten = \"a\"<br>print('Variable9: ', id(variable_nine))<br>print('Variable10: ', id(variable_ten))<\/pre>\n\n\n\n<p id=\"3ddd\">Notice, both the variables have the same memory location:<\/p>\n\n\n\n<p id=\"0d9d\">Variable9: 792473698064<br>Variable10: 792473698064<\/p>\n\n\n\n<p id=\"dadc\">What if we create two different variables and assign them a long string value:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">variable_nine = \"a\"*21<br>variable_ten = \"a\"*21<br>print('Variable9: ', id(variable_nine))<br>print('Variable10: ', id(variable_ten))<\/pre>\n\n\n\n<p id=\"89a5\">This time Python created two memory locations for the two variables:<\/p>\n\n\n\n<p id=\"fdf6\">Variable9: 541949933872<br>Variable10: 541949933944<\/p>\n\n\n\n<p id=\"a412\">This is because Python creates an internal cache of values when it starts up. This is done to provide faster results. It creates a handful of memory addresses for small integers such as between -5 to 256 and smaller string values. This is the reason why both of the variables in our example had the same ID.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:875\/0*_lg2u6mk9G_XR4AE\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Photo by&nbsp;<a href=\"https:\/\/unsplash.com\/@noahsilliman?utm_source=medium&amp;utm_medium=referral\" rel=\"noreferrer noopener\" target=\"_blank\">Noah Silliman<\/a>&nbsp;on&nbsp;<a href=\"https:\/\/unsplash.com\/?utm_source=medium&amp;utm_medium=referral\" rel=\"noreferrer noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"498b\">== vs is<\/h2>\n\n\n\n<p id=\"742e\">Sometimes we want to check whether two objects are equal.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If we use == then it will check whether the two arguments contain the same data<\/li>\n\n\n\n<li>If we use&nbsp;<em>is&nbsp;<\/em>then Python will check whether the two objects refer to the same object. The id() needs to be the same for both of the objects<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">var1 = \"a\"*30<br>var2 = \"a\"*30<br>print('var1: ', id(var1)) #318966315648<br>print('var2: ', id(var2)) #168966317364<br><br>print('== :', var1 == var2) #returns True<br>print('is :', var1 is var2) #returns False<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"564a\">8. Modules<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"52eb\">What is a module?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python is shipped with over 200 standard modules.<\/li>\n\n\n\n<li>A module is a component that groups similar functionality of your python solution.<\/li>\n\n\n\n<li>Any python code file can be packaged as a module and then it can be imported.<\/li>\n\n\n\n<li>Modules encourage componentised design in your solution.<\/li>\n\n\n\n<li>They provide the concept of namespaces to help you share data and services.<\/li>\n\n\n\n<li>Modules encourage code reusability and reduce variable name clashes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8f70\">PYTHONPATH<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This environment variable indicates where the Python interpreter needs to navigate to locate the modules. PYTHONHOME is an alternative module search path.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1ab7\">How To Import Modules?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you have a file: MyFirstPythonFile.py and it contains multiple functions, variables and objects then you can import the functionality into another class by simply doing:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">import MyFirstPythonFile<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Internally, python runtime will compile the module\u2019s file to bytes and then it will run the module code.<\/li>\n\n\n\n<li>If you want to import everything in a module, you can do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">import my_module<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If your module contains a function or object named my_object then you will have to do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">print(my_module.my_object)<\/pre>\n\n\n\n<p id=\"3838\"><strong>Note: If you do not want the interpreter to execute the module when it is loaded then you can check whether the __name__ == \u2018__main__\u2019<\/strong><\/p>\n\n\n\n<p id=\"0ce7\"><strong>2. From<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you only want to access an object or parts of a module from a module then you can implement:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">from my_module import my_object<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This will enable you to access your object without referencing your module:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">print(my_object)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can also do from * to import all objects<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">from my_module import *<\/pre>\n\n\n\n<p id=\"f551\"><strong><em>Note: Modules are only imported on the first import.<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>If you want to use a Python module in C:<\/strong><\/li>\n<\/ul>\n\n\n\n<p id=\"b0b0\"><em>Use PyImport_ImportModule(module_name)<\/em><\/p>\n\n\n\n<p id=\"4769\"><strong>Namespace \u2014 two modules with same object name<\/strong>:<\/p>\n\n\n\n<p id=\"dc2a\">Use import over from if we want to use the same name defined in two different modules.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a964\">9. Packages<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Package is a directory of modules.<\/li>\n\n\n\n<li>If your Python solution offers a large set of functionalities that are grouped into module files then you can create a package out of your modules to better distribute and manage your modules.<\/li>\n\n\n\n<li>Packages enable us to organise our modules better which helps us in resolving issues and finding modules easier.<\/li>\n\n\n\n<li>Third-party packages can be imported into your code such as pandas\/sci-kit learn and tensor flow to name a few.<\/li>\n\n\n\n<li>A package can contain a large number of modules.<\/li>\n\n\n\n<li>If our solution offers similar functionality then we can group the modules into a package:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">from packageroot.packagefolder.mod import my_object<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the example above, packageroot is the root folder. packagefolder is the subfolder under packageroot. my_module is a module python file in the packagefolder folder.<\/li>\n\n\n\n<li>Additionally, the name of the folder can serve as the namespace e.g.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">from data_service.database_data_service.microsoft_sql.mod<\/pre>\n\n\n\n<p id=\"4501\"><strong>Note: Ensure each directory within your package import contains a file __init__.py.<\/strong><\/p>\n\n\n\n<p id=\"b98a\"><strong>Feel free to leave the files blank. As __init__.py files are imported before the modules are imported, you can add custom logic such as start service status checks or to open database connections, etc.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5934\">PIP<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PIP is a Python package manager.<\/li>\n\n\n\n<li>Use PIP to download packages:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install package_name<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"62a3\">10. Conditions<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To write if then else:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">if a == b:<br>  print 'a is b'<br>elif a &lt; b:<br>  print 'a is less than b'<br>elif a &gt; b:<br>  print 'a  is greater than b'<br>else:<br>  print 'a is different'<\/pre>\n\n\n\n<p id=\"149a\"><em>Note how&nbsp;<\/em><strong><em>colons and indentations<\/em><\/strong><em>&nbsp;are used to express the conditional logic.<\/em><\/p>\n\n\n\n<p id=\"15b8\"><strong>Checking Types<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if not isinstance(input, int):<br>  print 'Expected int'<br>  return None<\/pre>\n\n\n\n<p id=\"604e\"><strong>You can also add conditional logic in the else part. This is known as nested condition.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#let's write conditions within else<br>else:<br> if a == 2:<br>    print 'within if of else'<br> else:<br>     print 'within else of else'<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"dc73\">11. Loops<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7c37\">While<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Provide a condition and run the loop until the condition is met:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">while (input &lt; 0):<br> do_something(input)<br> input = input-1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c805\">For<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Loop for a number of times<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">for  i in range(0,10)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Loop over items or characters of a string<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">for letter in 'hello'<br>  print letter<\/pre>\n\n\n\n<p id=\"221d\"><strong>One-Liner For<\/strong><\/p>\n\n\n\n<p id=\"f32b\">Syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Variable] AggregateFunction([Value] for [item] in [collection])<\/pre>\n\n\n\n<p id=\"e389\"><strong>Yielding<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let\u2019s assume your list contains a trillion records and you are required to count the number of even numbers from the list. It will not be optimum to load the entire list in the memory. You can instead yield each item from the list.<\/li>\n<\/ul>\n\n\n\n<p id=\"76fd\"><strong>range(start, stop, step):<\/strong><\/p>\n\n\n\n<p id=\"2235\">Generates numerical values that start at&nbsp;<em>start<\/em>, stop at&nbsp;<em>stop&nbsp;<\/em>with the provided&nbsp;<em>steps<\/em>. As an instance, to generate odd numbers from 1 to 9, do:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rint(list(range(1,10,2)))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b84b\"><strong>Combine For with If<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let\u2019s do a simple exercise to find if a character is in two words<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">name = 'onename'<br>anothername = 'onenameonename'for character in name:<br>  if character in anothername<br>     print character<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0c41\">Break<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to end the loop<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(0,10):<br> if (i==5):<br>   break<br>while True:<br>  x = get_value()<br>  if (x==1):<br>     break<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let\u2019s write Fibonacci for loop:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">def fib(input):<br> if (input &lt;=1):<br>   return(str(input))<br> else:<br>   first = 0<br>   second = 1<br>   count = 0<br>   for count in range(input):<br>     result = first + second<br>     print(first)<br>     first = second<br>     second = result<br>     count = count+1#print statement will output the correct fib value<br>fib(7)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"d88b\">12. Recursion<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A function calling itself is known as recursion.<\/li>\n<\/ul>\n\n\n\n<p id=\"b9d0\"><strong>Let\u2019s implement a factorial recursive function:<\/strong><\/p>\n\n\n\n<p id=\"68cf\"><strong>Rules<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>0! = 1 #Factorial of 0 is 1<\/li>\n\n\n\n<li>n! = n(n-1)! #Factorial of n is n * factorial of n-1<\/li>\n<\/ul>\n\n\n\n<p id=\"6f70\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a function called factorial with input n<\/li>\n\n\n\n<li>If n = 0 return 1 else do n x factorial of n-1<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">def factorial(n):<br>  if n==0:<br>    return 1<br>  else:<br>    return n * factorial(n-1)<\/pre>\n\n\n\n<p id=\"bbd2\"><strong>Another Example: Let\u2019s write Fibonacci recursive function:<\/strong><\/p>\n\n\n\n<p id=\"81bd\"><strong>Rules:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First two digits are 0 and 1<\/li>\n\n\n\n<li>Rest add last two digits<\/li>\n<\/ul>\n\n\n\n<p id=\"8183\">0, 1, 1, 2, 3, 5, 8\u2026<\/p>\n\n\n\n<p id=\"282d\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a function called fibonacci that takes in an input n<\/li>\n\n\n\n<li>Create two variables first and second and assign them with values 0 and 1<\/li>\n\n\n\n<li>if n =0 return 0, if n = 1 return 1 else return (n-1) + (n-2)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">def fibonacci(n):<br> if (n&lt;=1):<br>   return n<br> else:<br>   return fibonacci(n-1)+fibonacci(n-2)print(fibonacci(6))<\/pre>\n\n\n\n<p id=\"d37c\"><strong>It is important to have an exit check otherwise the function will end up in an infinite loop.<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3be4\">13. Frames And Call Stack<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python code is loaded into frames that are located into a Stack.<\/li>\n\n\n\n<li>Functions are loaded in a frame along with the parameters and variables.<\/li>\n\n\n\n<li>Subsequently, frames are loaded into a stack in the right order of execution.<\/li>\n\n\n\n<li>Stack outlines the execution of functions. Variables that are declared outside of functions are stored in __main__<\/li>\n\n\n\n<li>Stacks executes the last frame first.<\/li>\n<\/ul>\n\n\n\n<p id=\"96b2\">You can use&nbsp;<strong>traceback<\/strong>&nbsp;to find the list of functions if an error is encountered.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"9e78\">14. Collections<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9e3d\">Lists<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Lists are data structures that can hold a sequence of values of any data types. They are mutable (update-able).<\/li>\n\n\n\n<li>Lists are indexed by integers.<\/li>\n\n\n\n<li>To create a list, use square brackets:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_list = ['A', 'B']<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To add\/update\/delete an item, use index:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_list.append('C') #adds at the end<br>my_list[1] = 'D' #update<br>my_list.pop(1) # removes<br>or<br>del my_list[1:2] # removes<br>my_list.extend(another_list) # adds second list at end<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Addition, repetition and slices can be applied to lists (just like strings).<\/li>\n\n\n\n<li>List also supports sorting:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_list.sort() #this is inplace sort<\/pre>\n\n\n\n<p id=\"dbbd\">Note on pop():<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pop from the end is O(1)<\/li>\n\n\n\n<li>Pop from start (<code>.pop(0)<\/code>) is O(N) :&nbsp;<em>all<\/em>&nbsp;the elements in&nbsp;<code>list[1:]<\/code>&nbsp;are physically moved one position to the left.<\/li>\n<\/ul>\n\n\n\n<p id=\"7b17\">If you need to delete index position 0 frequently, use&nbsp;<code>collections.deque<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"00b2\">Tuples<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tuples are like lists in the sense that they can store a sequence of objects. The objects, again, can be of any type.<\/li>\n\n\n\n<li>Tuples are faster than lists.<\/li>\n\n\n\n<li>These collections are indexed by integers.<\/li>\n\n\n\n<li>Tuples are immutable (non-update-able)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_tuple = tuple()<br>or<br>my_tuple = 'f','m'<br>or<br>my_tuple = ('f', 'm')<\/pre>\n\n\n\n<p id=\"63d1\"><strong><em>Note: If a tuple contains a list of items then we can modify the list. Also if you assign a value to an object and you store the object in a list and then change the object then the object within the list will get updated.<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"688a\">Dictionaries<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Dictionary is one of the most important data structure in the programming world. It stores key\/value pair objects.<\/li>\n\n\n\n<li>It has many benefits e.g. optimised data retrieval functionality.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_dictionary = dict()<br>my_dictionary['my_key'] = 1<br>my_dictionary['another_key'] = 2<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can also create a dictionary as:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">my_dictionary = {'my_key':1, 'another_key':2}<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Print dictionary contents<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">for key in dictionary:<br>  print key, dictionary[key]<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Values of a dictionary can be of any type including strings, numerical, boolean, lists or even dictionaries.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">dictionary.items() # returns items#checking if a key exists in a dictionary<br>if ('some key' in dictionary):<br>  #do something<\/pre>\n\n\n\n<p id=\"b463\">Few of the important functions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">get(key, default): returns value for key else returns default<br>pop(key, default): returns value for key and deletes the item with key else returns default<br>popitem(): removes random item from the dictionarydictionary1.update(dictionary2): merges two dictionaries<\/pre>\n\n\n\n<p id=\"7fa7\"><strong><em>Note: If you want to perform vectorised\/matrix operations on a list then use NumPy Python package<\/em><\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6f05\">15. Compilation And Linking<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>These features can be utilised to use a file that is written in another language e.g. C or C++ etc, as long as it is supported by the compiler.<\/li>\n\n\n\n<li>Once the code is written into a file then the file can be placed in the Modules directory of the distribution.<\/li>\n\n\n\n<li>It is important to add a line in the Setup.local file to ensure that the newly created file can be loaded. Run the file using spam file.o<\/li>\n\n\n\n<li>Changing the file requires running rebuildMakefile<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ed43\">Compilation:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allows compilation of new extensions without any error<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"da2d\">Linking:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once the extensions are compiled, they can be linked.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"725e\">16. Iterators<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"71cc\">Iterators<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allow traversing through a collection<\/li>\n\n\n\n<li>All iterators contain __iter__() and __next__() functions<\/li>\n\n\n\n<li>Simply execute iter(x) on lists, dictionaries, strings or sets.<\/li>\n\n\n\n<li>Therefore we can execute next(iter) where iter = iter(list) as an instance.<\/li>\n\n\n\n<li>Iterators are useful if we have a large number of items in a collection and we do not intend to load all of the files in memory at once. Iterators are memory efficient and can represent an infinite stream.<\/li>\n\n\n\n<li>There are common iterators which enable developers to implement functional programming language paradigm:<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d429\"><strong>Filter<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Filter out values based on a condition<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5165\"><strong>Map<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Applies a computation on each value of a collection. It&nbsp;<strong>maps<\/strong>&nbsp;one value to another value e.g. Convert Text To Integers<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1c45\"><strong>Reduce<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reduces a collection of values to one single value (or a smaller collection) e.g. the sum of a collection. It can be iterative in nature.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d4bc\"><strong>Zip<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Takes multiple collections and returns a new collection.<\/li>\n\n\n\n<li>The new collection contains items where each item contains one element from each input collection.<\/li>\n\n\n\n<li>It allows us to transverse multiple collections at the same time<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">name = 'farhad'<br>suffix = [1,2,3,4,5,6]<br>zip(name, suffix)<br>--&gt; returns (f,1),(a,2),(r,3),(h,4),(a,5),(d,6)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c238\">enumerate<\/h2>\n\n\n\n<p id=\"299f\">enumerate can loop over an iterable and returns an automatic index for each of the elements:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for index, element in enumerate(iterator):<br>   pass<\/pre>\n\n\n\n<p id=\"087b\">Iterators require us to implement two key methods:<\/p>\n\n\n\n<p id=\"da24\">__iter__() and __next__()<\/p>\n\n\n\n<p id=\"06de\">Additionally, StopIteration needs to be raised when there are no values left to be returned.<\/p>\n\n\n\n<p id=\"5f2b\">We can make a function return an iterator by using a Generator. All we have to do is to use the&nbsp;<strong><em>yield&nbsp;<\/em><\/strong>keyword instead of&nbsp;<strong><em>return<\/em><\/strong>. The key is to yield one item at a time.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e0d1\">17. Object-Oriented Design \u2014 Classes<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python allows us to create our custom types. These user-defined types are known as classes. The classes can have custom properties\/attributes and functions.<\/li>\n\n\n\n<li>The object-oriented design allows programmers to define their business model as objects with their required properties and functions.<\/li>\n\n\n\n<li>A property can reference another object too.<\/li>\n\n\n\n<li>Python classes can reference other classes.<\/li>\n\n\n\n<li>Python supports encapsulation \u2014 instance functions and variables.<\/li>\n\n\n\n<li>Python supports inheritance.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class MyClass:<br>  def MyClassFunction(self):  #self = reference to the object<br>    return 5#Create new instance of MyClass and then call the function<br>m = MyClass()<br>returned_value = m.MyClassFunction()<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An instance of a class is known as an object. The objects are mutable and their properties can be updated once the objects are created.<\/li>\n<\/ul>\n\n\n\n<p id=\"5d01\"><strong><em>Note: If a tuple (immutable collection) contains a list (mutable collection) of items then we can modify the list. Also if you assign a value to an object and you store the object in a list and then change the object then the object within the list will get updated.<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e0f1\">__init__<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>__init__ function is present in all classes. It is executed when we are required to instantiate an object of a class. __init__ function can take any properties which we want to set:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class MyClass:<br>   def __init__(self, first_property):<br>       self.first_property = first_property   def MyClassFunction(self):<br>      return self.first_property<br>#Create an instance<br>m = MyClass(123)<br>r = m.MyClassFunction()r will be 123<\/pre>\n\n\n\n<p id=\"e290\"><strong><em>Note: self parameter will contain the reference of the object, also referred to as \u201cthis\u201d in other programming languages such as C#<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dbb7\">__str__<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Returns stringified version of an object when we call \u201cprint\u201d:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">m = MyClass(123)<br>print m #Calls __str__<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Therefore, __str__ is executed when we execute print.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"f538\">__cmp__<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the __cmp__ instance function if we want to provide custom logic to compare two objects of the same instance.<\/li>\n\n\n\n<li>It returns 1 (greater), -1 (lower) and 0 (equal) to indicate the equality of two objects.<\/li>\n\n\n\n<li>Think of __cmp__ like Equals() method in other programming language.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"15a8\">Overloading<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Methods of an object can be overloaded by providing more arguments as an instance.<\/li>\n\n\n\n<li>We can also overload an operator such as + by implementing our own implementation for __add__<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e7cb\">Shallow Vs Deep Copy Of Objects<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Equivalent objects \u2014 Contains the same values<\/li>\n\n\n\n<li>Identical objects \u2014 Reference the same object \u2014 same address in memory<\/li>\n\n\n\n<li>If you want to copy an entire object then you can use the copy module<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">import copy<br>m = MyClass(123)<br>mm = copy.copy(m)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This will result in shallow copy as the reference pointers of the properties will be copied.<\/li>\n\n\n\n<li>Therefore, if one of the properties of the object is an object reference then it will simply point to the same reference address as the original object.<\/li>\n\n\n\n<li>As a result, updating the property in the source object will result in updating the property in the target object.<\/li>\n\n\n\n<li>Therefore shallow copy copies reference pointers.<\/li>\n\n\n\n<li>Fortunately, we can utilise deep-copy:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">import copy<br>m = MyClass(123)<br>mm = copy.deepcopy(m)<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If MyClass contains a property that references MyOtherClass object then the contents of the property will be copied in the newly created object via deepcopy.<\/li>\n\n\n\n<li>Therefore, deep copy makes a new reference of the object.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e301\">18. Object-Oriented Design \u2014 Inheritance<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python supports the inheritance of objects. As a result, an object can inherit functions and properties of its parent.<\/li>\n\n\n\n<li>An inherited class can contain different logic in its functions.<\/li>\n\n\n\n<li>If you have a class: ParentClass and two subclasses: SubClass1, SubClass2 then you can use Python to create the classes as:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class ParentClass:<br> def my_function(self):<br>   print 'I am here'<br>class SubClass1(ParentClass):<br>class SubClass2(ParentClass):<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Consequently, both subclasses will contain the function my_function().<\/li>\n\n\n\n<li>Inheritance can encourage code reusability and maintenance.<\/li>\n<\/ul>\n\n\n\n<p id=\"5d96\"><strong><em>Note: Python supports multiple inheritances unlike C#<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use Python\u2019s abc module to ensure all subclasses contain the required features of the Abstract Base Class.<\/li>\n<\/ul>\n\n\n\n<p id=\"61db\"><strong>Multi-Inheritance:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class A(B,C):  #A implments B and C<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to call parent class function then you can do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">super(A, self).function_name()<\/pre>\n\n\n\n<p id=\"cf33\">There are a number of internal methods that we should be familiar with.<\/p>\n\n\n\n<p id=\"6c8f\">__str__(self): This function returns a user-friendly value to represent the object to the users.<\/p>\n\n\n\n<p id=\"90a1\">__repr__(self): This function returns a developer-friendly value to represent the object to the users. If __str__() is missing then __repr()__ is called.<\/p>\n\n\n\n<p id=\"0552\">__eq__(self, other): This function can help us compute how to find if two objects are equal.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Human:<br>    def __init__(self, name, friends=[]):<br>        self.name = name<br>        self.friends = friends<br><br>    def __str__(self):<br>        return f'Name is: {self.name}'<br><br>    def __repr__(self):<br>        return 'Human({self.name}, {self.friends})'<br><br>    def __eq__(self, other):<br>        return self.name == other.name<br><br><br>human = Human('Farhad', ['Friend1', 'Friend2'])<br>print(human)<\/pre>\n\n\n\n<p id=\"39c2\">This will print: Name is: Farhad<\/p>\n\n\n\n<p id=\"5b81\">If we remove __str__ function then it will call __repr__ instead:<\/p>\n\n\n\n<p id=\"367c\">This will print: Human(Farhad, [\u2018Friend1\u2019, \u2018Friend2\u2019])<\/p>\n\n\n\n<p id=\"904c\">If we create two human instances with the same name and different friends then it will mark both of them as equal due to the __eq__ function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">human1 = Human('Farhad', ['Friend1', 'Friend2'])<br>human2 = Human('Farhad', ['ABC', 'DEF'])<br>print(human1 == human2) #prints True<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"9511\">19. Garbage Collection \u2014 Memory Management<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All of the objects in Python are stored in heap space. This space is accessible to the Python interpreter. It is private.<\/li>\n\n\n\n<li>Python has an in-built garbage collection mechanism.<\/li>\n\n\n\n<li>It means Python can allocate and de-allocate the memory for your program automatically such as in C++ or C#.<\/li>\n\n\n\n<li>Its responsibility is to clear the space in memory of those objects that are not referenced\/used in the program.<\/li>\n<\/ul>\n\n\n\n<p id=\"ec67\">As multiple objects can share memory references, python employs two mechanisms:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Reference counting:<\/strong>&nbsp;Count the number of items an object is referenced, deallocate an object if its count is 0. The reference is incremented when the variable is assigned an object or when it is passed as an argument to any method.<\/li>\n\n\n\n<li>The second mechanism takes care of circular references, also known as&nbsp;<strong>cyclic references<\/strong>, by only de-allocating the objects where the allocation \u2014 deallocation number is greater than the threshold.<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>New objects are created in Generation 0 in python. They can be inspected by:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">import gc<br>collected_objects = gc.collect()<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Manual garbage collection can be performed on a timely or event-based mechanism.<\/li>\n\n\n\n<li>When a Python program exists then Python attempts to remove global objects and ones that have a circular reference.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"10c5\">20. I\/O<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"93aa\">From Keyboard<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the raw_input() function<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">user_says = raw_input()<br>print(user_says)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2f2d\">Files<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use a with\/as a statement to open and read a file. It is equivalent to the using statement in C#.<\/li>\n\n\n\n<li>with statement can take care of the closing of connections and other cleanup activities.<\/li>\n<\/ul>\n\n\n\n<p id=\"735a\"><strong>Open files<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">with open(file path, 'r') as my_file:<br>  for line in my_file#File is closed due to with\/as<\/pre>\n\n\n\n<p id=\"cc77\"><strong>Note: readline() can also be executed to read a line of a file.<\/strong><\/p>\n\n\n\n<p id=\"43de\"><strong>To open two files<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">with open(file path) as my_file, open(another path) as second_file:<br>  for (line number, (line1, line2)) in enumerate(zip(my_file, second_file):<\/pre>\n\n\n\n<p id=\"0cd7\"><strong>Writing files<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">with open(file path, 'w') as my_file:<br>  my_file.write('test')<\/pre>\n\n\n\n<p id=\"9071\"><strong><em>Note: Use os and shutil modules for files.<\/em><\/strong><\/p>\n\n\n\n<p id=\"24b3\"><strong><em>Note: There are a large number of modes available, such as:<\/em><\/strong><\/p>\n\n\n\n<p id=\"8904\"><em>rw \u2014 read-write mode<\/em><\/p>\n\n\n\n<p id=\"88da\"><em>r \u2014 read mode<\/em><\/p>\n\n\n\n<p id=\"cd09\"><em>rb \u2014 read in binary format mode e.g. pickle file<\/em><\/p>\n\n\n\n<p id=\"2b7e\"><em>r+ \u2014 read for both reading and writing mode<\/em><\/p>\n\n\n\n<p id=\"d048\"><em>a \u2014 append mode.<\/em><\/p>\n\n\n\n<p id=\"9146\">w+ \u2014 for reading and writing, overwrites if the file exists<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4b3b\">SQL<\/h2>\n\n\n\n<p id=\"2aa5\"><strong>Open a connection<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import MySQLdb<br>database = MySQLdb.connect(\u201chost\u201d=\u201dserver\u201d, \u201cdatabase-user\u201d=\u201dmy username\u201d, \u201cpassword\u201d=\u201dmy password\u201d, \u201cdatabase-name\u201d=\u201dmy database\u201d)<br>cursor = database.cursor()<\/pre>\n\n\n\n<p id=\"812e\"><strong>Execute a SQL statement<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cursor.fetch(\"Select * From MyTable\")<br>database.close()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e323\">Web Services<\/h2>\n\n\n\n<p id=\"9703\"><strong>To query a rest service<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import requests<br>url = 'http:\/\/myblog.com'<br>response = requests.get(url).text<\/pre>\n\n\n\n<p id=\"5bf0\"><strong>To Serialise and Deserialise JSON<\/strong><\/p>\n\n\n\n<p id=\"6371\"><strong>Deserialise<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import json<br>my_json = {\"A\":\"1\",\"B\":\"2\"}<br>json_object = json.loads(my_json)<br>value_of_B = json_object[\"B\"]<\/pre>\n\n\n\n<p id=\"7c0a\"><strong>Serialise<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import json<br>a = \"1\"<br>json_a = json.dumps(a)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"dc8c\">21. Error Handling<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2f24\">Raise Exceptions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to raise exceptions then use the raise keyword:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>  raise TypError<br>except:<br>  print('exception')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e199\">Catching Exceptions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To catch exceptions, you can do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>   do_something()<br>except:<br>   print('exception')<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to catch specific exceptions then you can do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>   do_something()<br>except TypeError:<br>   print('exception')<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to use try\/catch\/finally then you can do:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>   do_something()<br>except TypeError:<br>   print('exception')<br>finally:<br>   close_connections()<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>finally part of the code is triggered regardless, you can use finally to close the connections to database\/files, etc.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9be5\">Try\/Except\/Else<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>  do something<br>except IfTryRaisedException1:<br>  do something else<br>except (IfTryRaisedException2, IfTryRaisedException3)<br>  if exception 2 or 3 is raised then do something<br>else:<br>  no exceptions were raised<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>else is executed when no exceptions have been raised.<\/li>\n\n\n\n<li>We can also assign exception to a variable by doing:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">try:<br>  do something<br>except Exception1 as my_exception:<br>  do something about my_exception<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to define user-defined constraints then use assert:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">assert &lt;bool&gt;, 'error to throw'<\/pre>\n\n\n\n<p id=\"f967\"><strong><em>Note: Python supports inheritance in exceptions<\/em><\/strong><\/p>\n\n\n\n<p id=\"d8f1\">You can create your own exception class by:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class MyException(Exception): pass<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e9cb\">22. Multi-Threading And GIL<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>GIL is Global Interpreter Lock.<\/li>\n\n\n\n<li>It ensures that the threads can execute at any one time and allows CPU cycles to pick the required thread to be executed.<\/li>\n\n\n\n<li>GIL is passed onto the threads that are currently being executed.<\/li>\n\n\n\n<li>Python supports multi-threading.<\/li>\n<\/ul>\n\n\n\n<p id=\"b5b9\"><em>Note: GIL adds overheads to the execution. Therefore, be sure that you want to run multiple threads.<\/em><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"1ceb\">23. Decorators<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Decorators can add functionality to code. They are essentially functions that call other objects\/functions.<\/li>\n\n\n\n<li>Decorators are callable functions \u2014 therefore they return the object to be called later when the decorated function is invoked.<\/li>\n\n\n\n<li><em>Think of decorates that enable aspect-oriented programming<\/em><\/li>\n\n\n\n<li>We can wrap a class\/function and then a specific code will be executed any time the function is called.<\/li>\n\n\n\n<li><em>We can implement generic logic to log, check for security checks, etc and then attribute the method with the&nbsp;<\/em><strong><em>@property tag.<\/em><\/strong><\/li>\n\n\n\n<li>The most important concept to understand is that in Python, functions are objects. This means a function can return another function and one function can take another function as an argument. We can also define a function within another function. Functions can also be assigned to a variable.<\/li>\n<\/ul>\n\n\n\n<p id=\"c594\"><strong>Understanding decorators:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Essentially a decorator is a function. It accepts another function as a parameter. It also returns a function. Let\u2019s understand the steps:<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The decorator is a function that accepts a function as an input and returns an inner function:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">def my_decorator(input):  def my_inner_decorator(*args, **kwargs):<br>     print('Hi FinTechExplained')<br>     input(*args, **kwargs)<br>     print('Bye FinTechExplained')<br>  <br>  return my_inner_decorator<\/pre>\n\n\n\n<p id=\"d64a\">2. The input function is the one that the decorator is going to decorate.<\/p>\n\n\n\n<p id=\"d337\">3. The internal function is the function that performs the appropriate actions to the input function and then the decorator returns the inner function.<\/p>\n\n\n\n<p id=\"3940\">To use the decorator, use the @ sign:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@my_decorator<br>def print_num(number):<br>  print('inside function:',number)print_num(1)The function printed:<br>Hi FinTechExplained<br>inside function: 1<br>Bye FinTechExplained<\/pre>\n\n\n\n<p id=\"774b\">We can also pass other parameters to the decorator if required.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"76b0\">24. Unit Testing In Python<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>There are a number of unit testing and mocking libraries available in Python.<\/li>\n\n\n\n<li>An example is to use&nbsp;<strong>unittest<\/strong>:<\/li>\n<\/ul>\n\n\n\n<p id=\"2f66\">1.Assume your function simply decrements an input by 1<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def my_function(input):<br>  return input - 1<\/pre>\n\n\n\n<p id=\"7a6f\">2. You can unit test it by:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import unittest<br>class TestClass(unittest.TestCase):<br> def my_test(self):<br>    self.assertEqual(my_function(1), 0)) #checking 1 becomes 0<\/pre>\n\n\n\n<p id=\"15f7\">We can also use&nbsp;<strong>doctest<\/strong>&nbsp;to test code written in docstrings.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6fb9\">25. Top Python Discussion Questions<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e9bd\">Why Should I Use Python?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simple to code and learn<\/li>\n\n\n\n<li>Object-oriented programming language<\/li>\n\n\n\n<li>Great Analytics and ML packages<\/li>\n\n\n\n<li>Faster to develop and bring my solution to market<\/li>\n\n\n\n<li>Offers in-built memory management facilities<\/li>\n\n\n\n<li>Huge community support and applications available<\/li>\n\n\n\n<li>No need to compile as it\u2019s an interpreted language<\/li>\n\n\n\n<li>Dynamically typed \u2014 no need to declare variables<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"53d6\">How To Make Python Run Fast?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python is a high-level language and is not suitable to access system-level programs or hardware.<\/li>\n\n\n\n<li>Additionally, it is not suitable for cross-platform applications.<\/li>\n\n\n\n<li>The fact that Python is a dynamically typed interpreted language makes it slower to be optimised and run when compared to the low-level languages.<\/li>\n\n\n\n<li>Implement C language-based extensions.<\/li>\n\n\n\n<li>Create multi-processes by using Spark or Hadoop<\/li>\n\n\n\n<li>Utilise Cython, Numba, and PyPy to speed up your Python code or write it in C and expose it in Python like NumPy<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9eaa\">Which IDEs Do People Use?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Spyder, PyCharm. Additionally various notebooks are used e.g. Jupyter<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"34fb\">What Are The Top Python Frameworks And Packages?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>There are a large number of must-use packages:<\/li>\n<\/ul>\n\n\n\n<p id=\"0566\">PyUnit (unit testing), PyDoc (documentation), SciPy (algebra and numerical), Pandas (data management), Sci-Kit learn (ML and data science), Tensorflow (AI), Numpy (array and numerical), BeautifulSoap (web pages scrapping), Flask (microframework), Pyramid (enterprise applications), Django (UI MVVM), urllib (web pages scraping), Tkinter (GUI), mock (mocking library), PyChecker(bug detector), Pylint (module code analysis)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"98c9\">How To Host Python Packages?<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>For Unix: Make script file mode Executable and the first line begin with:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">#(#!\/my account\/local\/bin\/python)<\/pre>\n\n\n\n<p id=\"30ff\">2. You can use command-line tool and execute it<\/p>\n\n\n\n<p id=\"c31b\">3. Use PyPRI or PyPI server<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5c5e\">Can Python and R be combined?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A large number of rich statistical libraries have been written in R<\/li>\n\n\n\n<li>One can execute R code within Python by using Rpy2 python package or by using a beaker notebook or IR kernel within Jupyter.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2325\">Is there a way to catch errors before running Python?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can use PyChecker and PyLink to catch errors before running the code.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ea74\">Summary<\/h1>\n\n\n\n<p id=\"7d06\">This article outlined the most important 25 concepts of Python in a&nbsp;<strong>short, relevant and focused manner.<\/strong>&nbsp;I genuinely hope it has helped someone get a better understanding of Python.<\/p>\n\n\n\n<p id=\"baf9\">I believe I have concentrated on the must-know topics that are absolutely required to be understood. This knowledge is sufficient to write your own python packages in the future or using existing Python packages.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:875\/1*9AGcZ7S7bxMCO35PLHXyyQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Thank you for reading.<\/figcaption><\/figure>\n\n\n\n<p id=\"b0cf\"><strong>Rest, just practice as much as possible and you can implement your own library in Python because this article contains all the knowledge you need.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article aims to outline all of the key points of the Python programming language. My target is to keep the information&nbsp;short, relevant, and focus&nbsp;on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[5],"class_list":["post-12","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Everything you need to learn about Python - Farrukh&#039;s Tech Space<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Everything you need to learn about Python - Farrukh&#039;s Tech Space\" \/>\n<meta property=\"og:description\" content=\"This article aims to outline all of the key points of the Python programming language. My target is to keep the information&nbsp;short, relevant, and focus&nbsp;on [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Farrukh&#039;s Tech Space\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-12T17:14:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-13T17:23:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/2019-10-python-everything-you-should-know-1024x576-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Farrukh Naveed Anjum\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Farrukh Naveed Anjum\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"34 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\"},\"author\":{\"name\":\"Farrukh Naveed Anjum\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/ce7d07e6a917b9b73aa79007a2357d29\"},\"headline\":\"Everything you need to learn about Python\",\"datePublished\":\"2023-06-12T17:14:33+00:00\",\"dateModified\":\"2023-09-13T17:23:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\"},\"wordCount\":6129,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#organization\"},\"keywords\":[\"Python\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\",\"url\":\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\",\"name\":\"Everything you need to learn about Python - Farrukh&#039;s Tech Space\",\"isPartOf\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#website\"},\"datePublished\":\"2023-06-12T17:14:33+00:00\",\"dateModified\":\"2023-09-13T17:23:02+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#website\",\"url\":\"https:\/\/farrukhnaveed.co\/blogs\/\",\"name\":\"Farrukh Naveed Anjum Blogs\",\"description\":\"Empowering Software Architects with Knowledge on Big Data and AI\",\"publisher\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/farrukhnaveed.co\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#organization\",\"name\":\"Farrukh Naveed Anjum Blogs\",\"url\":\"https:\/\/farrukhnaveed.co\/blogs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/IMG_5018-scaled.jpg\",\"contentUrl\":\"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/IMG_5018-scaled.jpg\",\"width\":1707,\"height\":2560,\"caption\":\"Farrukh Naveed Anjum Blogs\"},\"image\":{\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/ce7d07e6a917b9b73aa79007a2357d29\",\"name\":\"Farrukh Naveed Anjum\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bdf1af0d569259df562434e6dc99415a377c6fc053f9e1507aa34a6522561bb8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bdf1af0d569259df562434e6dc99415a377c6fc053f9e1507aa34a6522561bb8?s=96&d=mm&r=g\",\"caption\":\"Farrukh Naveed Anjum\"},\"description\":\"Full Stack Developer and Software Architect with 14 years of experience in various domains, including Enterprise Resource Planning, Data Retrieval, Web Scraping, Real-Time Analytics, Cybersecurity, NLP, ED-Tech, and B2B Price Comparison\",\"sameAs\":[\"https:\/\/farrukhnaveed.co\/blog\"],\"url\":\"https:\/\/farrukhnaveed.co\/blogs\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Everything you need to learn about Python - Farrukh&#039;s Tech Space","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/","og_locale":"en_US","og_type":"article","og_title":"Everything you need to learn about Python - Farrukh&#039;s Tech Space","og_description":"This article aims to outline all of the key points of the Python programming language. My target is to keep the information&nbsp;short, relevant, and focus&nbsp;on [&hellip;]","og_url":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/","og_site_name":"Farrukh&#039;s Tech Space","article_published_time":"2023-06-12T17:14:33+00:00","article_modified_time":"2023-09-13T17:23:02+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/2019-10-python-everything-you-should-know-1024x576-1.jpg","type":"image\/jpeg"}],"author":"Farrukh Naveed Anjum","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Farrukh Naveed Anjum","Est. reading time":"34 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/#article","isPartOf":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/"},"author":{"name":"Farrukh Naveed Anjum","@id":"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/ce7d07e6a917b9b73aa79007a2357d29"},"headline":"Everything you need to learn about Python","datePublished":"2023-06-12T17:14:33+00:00","dateModified":"2023-09-13T17:23:02+00:00","mainEntityOfPage":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/"},"wordCount":6129,"commentCount":0,"publisher":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/#organization"},"keywords":["Python"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/","url":"https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/","name":"Everything you need to learn about Python - Farrukh&#039;s Tech Space","isPartOf":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/#website"},"datePublished":"2023-06-12T17:14:33+00:00","dateModified":"2023-09-13T17:23:02+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/farrukhnaveed.co\/blogs\/everything-you-need-to-learn-about-python\/"]}]},{"@type":"WebSite","@id":"https:\/\/farrukhnaveed.co\/blogs\/#website","url":"https:\/\/farrukhnaveed.co\/blogs\/","name":"Farrukh Naveed Anjum Blogs","description":"Empowering Software Architects with Knowledge on Big Data and AI","publisher":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/farrukhnaveed.co\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/farrukhnaveed.co\/blogs\/#organization","name":"Farrukh Naveed Anjum Blogs","url":"https:\/\/farrukhnaveed.co\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/IMG_5018-scaled.jpg","contentUrl":"https:\/\/farrukhnaveed.co\/blogs\/wp-content\/uploads\/2023\/06\/IMG_5018-scaled.jpg","width":1707,"height":2560,"caption":"Farrukh Naveed Anjum Blogs"},"image":{"@id":"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/ce7d07e6a917b9b73aa79007a2357d29","name":"Farrukh Naveed Anjum","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/farrukhnaveed.co\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/bdf1af0d569259df562434e6dc99415a377c6fc053f9e1507aa34a6522561bb8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bdf1af0d569259df562434e6dc99415a377c6fc053f9e1507aa34a6522561bb8?s=96&d=mm&r=g","caption":"Farrukh Naveed Anjum"},"description":"Full Stack Developer and Software Architect with 14 years of experience in various domains, including Enterprise Resource Planning, Data Retrieval, Web Scraping, Real-Time Analytics, Cybersecurity, NLP, ED-Tech, and B2B Price Comparison","sameAs":["https:\/\/farrukhnaveed.co\/blog"],"url":"https:\/\/farrukhnaveed.co\/blogs\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":10,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/posts\/12\/revisions\/83"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/media\/13"}],"wp:attachment":[{"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/farrukhnaveed.co\/blogs\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}