{"id":747,"date":"2019-02-04T01:28:38","date_gmt":"2019-02-04T01:28:38","guid":{"rendered":"http:\/\/www.afternerd.com\/blog\/?p=747"},"modified":"2023-06-03T05:43:53","modified_gmt":"2023-06-03T05:43:53","slug":"learn-python","status":"publish","type":"post","link":"https:\/\/www.afternerd.com\/blog\/learn-python\/","title":{"rendered":"Best Way to Learn Python [Massive 2023 Step-by-Step Guide]"},"content":{"rendered":"\n<p>Python is a very popular language.<\/p>\n<p>It&#8217;s also one of the languages that I recommend for beginners to start with.<\/p>\n<p><em>But what is the best way to learn Python?<\/em><\/p>\n<p>In this article, I divide the <em>Python learning path<\/em> into <strong>6 levels.&nbsp;<\/strong>And I will teach you how to navigate these levels, one level at a time step-by-step until you reach Python mastery.<\/p>\n<p>Each level covers a subset of the language that you need to master before you move on to the next one.<\/p>\n<p>My focus on this article is for you to be a competent well-rounded programmer so you can easily get a job at any tech company that you choose.<\/p>\n<div class=\"after-post-box\">\n<h2>What is the best way to learn Python?<\/h2>\n<p>The best way to learn Python is to progress through these levels one level at a time. Make sure you completely understand and have extensive hands-on experience at each level before you move to the next one. This means you need to actually open your laptop and write code. A lot of code. Do that and you will be on your way to Python mastery!<\/p>\n<\/div>\n<p>Let&#8217;s get started.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1339 size-full\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/h2>\n<h2 id=\"level0\">Level 0: The Beginnings<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1360\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking.jpg\" alt=\"\" width=\"850\" height=\"504\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking.jpg 850w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-300x178.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-768x455.jpg 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-200x119.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-400x237.jpg 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-600x356.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/lionking-800x474.jpg 800w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>This is the level you begin at if you are an <em>absolute beginner<\/em>.<\/p>\n<p>And by <strong>absolute beginner<\/strong>, I mean someone who has never coded before in Python or any other programming language for that matter.<\/p>\n<p>If you are coming from a different programming language, then <a href=\"#level1\" data-abc=\"true\">you should skip to level 1<\/a>.<\/p>\n<div class=\"after-post-box\">\n<h3>\ud83d\udcda Python Courses<\/h3>\n<p>\ud83d\udc76&nbsp;For Level 0: <a href=\"https:\/\/www.youtube.com\/watch?v=OE4fByQj4Mw&amp;list=PLEJiGYvExt32i_b2vJHFxCmdb50cCKeyH\" target=\"_blank\" rel=\"noopener\" data-abc=\"true\">Check out my YouTube playlist<\/a>.<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ad.linksynergy.com\/fs-bin\/show?id=J09lQDk70gY&amp;bids=507388.567828&amp;type=2&amp;subid=0\" width=\"1\" height=\"1\" border=\"0\"><\/p>\n<p>\ud83d\ude80 For Level 1: Check out my <strong>Object-Oriented Programming Course<\/strong> on <a href=\"https:\/\/www.afternerd.com\/udemy\/python-oop-course?origin=web\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Udemy<\/a> or on my <a target=\"_blank\" href=\"https:\/\/courses.afternerd.com\/p\/python-oop-course\/?referral=learn-python\" rel=\"noopener\">website<\/a> (check both to see if there is a sale on any)<\/p>\n<\/div>\n<p>At this level, most of the concepts you will be learning are general programming concepts. The fundamental skills that will bootstrap you as a programmer.<\/p>\n<p>This means that these concepts are not really exclusive to Python but can be extended to other programming languages as well.<\/p>\n<p>You see, a lot of programming languages are very similar, and knowing what\u2019s common (and what&#8217;s not) between programming languages will help you transition into a different one in the future.<\/p>\n<div class=\"after-post-box\">\n<h2>Python 3 Cheat Sheet for Beginners<\/h2>\n<p><img decoding=\"async\" style=\"border: 5px solid #f18225\" src=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-24-at-8.42.42-AM.png\"><\/p>\n<p>Download a comprehensive cheat sheet for beginners with extensive code examples that covers all the topics that you need to learn.<br \/>\n<script type=\"text\/javascript\" src=\"\/\/mautic.afternerd.com\/form\/generate.js?id=9\"><\/script>\n<\/div>\n\n<p><em>So what are some of these general programming concepts that I am talking about?<\/em><\/p>\n<p>Some of these fundamental concepts are variables, data types, operations, functions, conditionals, and loops.<\/p>\n<p>If you understand what these concepts are, <a href=\"#level1\" data-abc=\"true\">then skip to level 1<\/a>.<\/p>\n<p>Otherwise, Let me give you a <strong>very brief<\/strong> introduction about what these concepts mean.<\/p>\n<h3>Variables<\/h3>\n<p>Variables are essentially <strong>storage<\/strong> for data in your program.<\/p>\n<p>More accurately, it&#8217;s a way of <em>giving a name<\/em> for data for later use.<\/p>\n<p>Let&#8217;s look at an example.<\/p>\n<pre class=\"prettyprint\"><code># variables\nmsg = \"Hello World!\"\nprint(msg)\n#&nbsp;this&nbsp;code outputs&nbsp;Hello&nbsp;World!&nbsp;on&nbsp;the&nbsp;screen<\/code><\/pre>\n<p>In the Python snippet above, we define a variable <span class=\"symbol\">msg<\/span> that stores the value <strong>Hello World!<\/strong><\/p>\n<p>This allows us to later print Hello World! on the screen by just using the variable name that stores this value instead of having to type the value <strong>Hello World!&nbsp;<\/strong>every time we want to use it.<\/p>\n<h3>Data Types<\/h3>\n<p>We talked about variables as storage for data, now let&#8217;s talk about data.<\/p>\n<p>In Python, data has types.<\/p>\n<p>For example, in the code snippet above, the data <strong>Hello World!<\/strong> has a specific type that Python (and other programming languages) call <strong>string.<\/strong><\/p>\n<p>A <strong>String<\/strong> is simply a sequence of characters.<\/p>\n<p>But strings aren&#8217;t the only data type in Python, there are also <em>integers<\/em>, <em>floating-point numbers<\/em>, <em>boolean<\/em>, <em>lists<\/em>, <em>tuples<\/em>, and <em>dictionaries<\/em>.<\/p>\n<p>By the end of level 0, you need to be comfortable with these data types and understand when (and how) to use them in your program.<\/p>\n<h3>Operations<\/h3>\n<p><em>Operations<\/em> is how you manipulate and change data in your program.<\/p>\n<p>In other words, your programs need to operate on data and produce more data, that you also operate on, until you reach the final outcome.<\/p>\n<p>This is just the lifecycle of any program.<\/p>\n<p>In Python and all programming languages, there exists at least <em>Arithmetic<\/em>, <em>Comparison<\/em>, and <em>Logic<\/em> operations.<\/p>\n<pre class=\"prettyprint\"><code># an example of an arithmetic operation\nx = 5 + 2\n\n# an example of a comparison operation\ny = 3 &gt; 4\n\n# an example of a logic operation\nz = True or False<\/code><\/pre>\n<h3>Conditionals<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1366\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional.jpg\" alt=\"\" width=\"1440\" height=\"697\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional.jpg 1440w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-300x145.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-768x372.jpg 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-1024x496.jpg 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-200x97.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-400x194.jpg 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-600x290.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-800x387.jpg 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/if-conditional-1200x581.jpg 1200w\" sizes=\"(max-width: 1440px) 100vw, 1440px\" \/><\/p>\n<p>In order to write any program that is useful, you almost always will need the ability to check conditions and change the behavior of the program accordingly.<\/p>\n<p>Conditional statements using <span class=\"symbol\">if<\/span>, <span class=\"symbol\">if else<\/span>, or <span class=\"symbol\">if elsif else<\/span> gives you this ability.<\/p>\n<p>Here is an example of an if-else statement in Python.<\/p>\n<pre class=\"prettyprint\"><code>&gt;&gt;&gt; if 3 &gt; 5:\n...   print('3 is greater than 5')\n... else:\n...   print('3 is not greater than 5')\n...\n3 is not greater than 5<\/code><\/pre>\n<h3>Functions<\/h3>\n<p class=\"intro\">A function is essentially a block of Python code that only runs when it is <em>called<\/em>.<\/p>\n<p class=\"intro\">You can pass parameters into a function as input and a function can return data as output.<\/p>\n<p class=\"intro\">In Python, you define a function using the <strong>def<\/strong> keyword.<\/p>\n<p>Here is an example of a hello world program using a function <span class=\"symbol\">say_hello<\/span><\/p>\n<pre class=\"prettyprint\"><code>def say_hello(msg):\n  # this is the function\n  # msg is the input parameter\n  print(f'hello {msg}')\n\n# calling the say_hello function\nsay_hello('world')\n\n# output:\n# hello world<\/code><\/pre>\n<hr>\n<p>So this was an example of the fundamental concepts that you should learn at this level.<\/p>\n<p>But most importantly, what you really need to do in order to master this level is to use the above concepts to<em> solve problems.<\/em><\/p>\n<p>You will never be a good programmer if all that you do is read books or take courses.<\/p>\n<p>You need to practice solving problems so get your hands dirty and start solving simple problems using Python. You can start by solving <a href=\"https:\/\/projecteuler.net\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Project Euler<\/a> problems.<\/p>\n<p>I can&#8217;t stress enough the importance of <strong>mastering level 0<\/strong>.<\/p>\n<p>The reason for that is, this level lays the foundation and the fundamental concepts for not only mastering Python but mastering any other programming language as well.<\/p>\n<p>So even though this is level 0, don&#8217;t take it lightly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1342\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-1.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-1.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-1-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-1-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-0-1-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2 id=\"level1\">Level 1:&nbsp;Object-oriented Programming<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1362\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop.jpg\" alt=\"\" width=\"1248\" height=\"744\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop.jpg 1248w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-300x179.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-768x458.jpg 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-1024x610.jpg 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-200x119.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-400x238.jpg 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-600x358.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-800x477.jpg 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/cars-oop-1200x715.jpg 1200w\" sizes=\"(max-width: 1248px) 100vw, 1248px\" \/><\/p>\n<div class=\"after-post-box\">If you are at this level, then I have a course that will teach you everything you need to know about object-oriented programming. <a href=\"https:\/\/www.udemy.com\/course\/python-oop-course\/?referralCode=C7ED0BBE784449E0E6E7\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Check it out here<\/a> \ud83d\ude42<\/div>\n<p>Everything in Python is an object.<\/p>\n<p>You either heard this already, or you are destined to hear about it \ud83d\ude42<\/p>\n<p><em>But wait a minute, what exactly is an object?<\/em><\/p>\n<p>There are many different ways, models, or paradigms to write computer programs.<\/p>\n<p>One of the most popular programming paradigms is called object-oriented programming (OOP).<\/p>\n<p><iframe loading=\"lazy\" title=\"What is Object-Oriented Programming? (The basic concepts)\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/kZ_IRwqEW-g?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>In object-oriented programming, an&nbsp;<i>object<\/i>&nbsp;refers to a particular instance of a&nbsp;<em>Class<\/em>.<\/p>\n<p>And a <strong>Class<\/strong> is like a blueprint of the <em>state<\/em> and <em>actions<\/em> that an object can take.<\/p>\n<p>For example, in Python, a <strong>Person Class<\/strong> might look something like this.<\/p>\n<pre class=\"prettyprint\"><code>class Person:\n  def __init__(self, name, age):\n    self.name = name\n    self.age = age\n  \n  def get_name(self):\n    return self.name<\/code><\/pre>\n<p>The class declared above describes the state and actions of any <strong>Person<\/strong> object.<\/p>\n<p>For example, any Person object will have a <strong>name<\/strong> and an <strong>age<\/strong>. These two fields are what determines the <em>state<\/em> of the object.<\/p>\n<p>In OOP&#8217;s terminology, <strong>name<\/strong> and <strong>age<\/strong> are called the object <em>attributes<\/em>.<\/p>\n<p>You can also call <span class=\"symbol\">get_name()<\/span> on any <strong>Person<\/strong> object to return the name of the person.<\/p>\n<p>We call <strong>get_name<\/strong> a <em>method. <\/em><\/p>\n<p><em>A<\/em>nd this method, in addition to any other methods that we define, is what determines the object&#8217;s <em>actions<\/em>.<\/p>\n<p>In other words, a Python object has <em>attributes<\/em> and <em>methods<\/em> that are defined in the object&#8217;s <em>Class<\/em>.<\/p>\n<p>Here&#8217;s how to create a <strong>Person<\/strong> object<\/p>\n<pre class=\"prettyprint\"><code>&gt;&gt;&gt; p = Person('Alice', 22)\n&gt;&gt;&gt; p.get_name()\n'Alice'<\/code><\/pre>\n<p>Object-oriented programming is essentially one way of structuring and designing your code.<\/p>\n<p>However, I want you to understand that it is not the only way, and it is not necessarily the best way.<\/p>\n<p>In order to learn OOP in Python, you need to progress through a few steps.<\/p>\n<h3>Step 1: Learn the concepts of OOP<\/h3>\n<p>As I mentioned earlier, OOP is a programming paradigm, a way of structuring and designing your code.<\/p>\n<p>OOP concepts are not exclusive to Python so the concepts you will learn will easily transition to any other programming language.<\/p>\n<p>Some examples of these concepts are <a href=\"https:\/\/en.wikipedia.org\/wiki\/Inheritance_(object-oriented_programming)\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">inheritance<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Encapsulation_(computer_programming)\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">encapsulation<\/a>, and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Polymorphism_(computer_science)\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">polymorphism<\/a>.<\/p>\n<p>So make sure you understand these concepts at an abstract level first before you jump into Python&#8217;s OOP.<\/p>\n<h3>Step 2: Learn about Python&#8217;s Classes and Objects<\/h3>\n<p>In this step, you need to apply the abstract concepts you learned in the previous step but specifically in Python.<\/p>\n<p>Get comfortable with writing Classes and creating Objects.<\/p>\n<p>Write classes that inherit from other classes and investigate the attributes and methods of the objects created.<\/p>\n<h3>Step 3: Solve Python problems using OOP<\/h3>\n<p>This is a crucial step.<\/p>\n<p>In this step, you want to learn how to use OOP to design and structure your code.<\/p>\n<p>And as a matter of fact, this step is more of an art than a science. That means the only way to get better is through practice, practice, and more practice.<\/p>\n<p>Again keep solving more problems using Python, but try to structure your solutions in an object-oriented way.<\/p>\n<p>The more you practice, the more you will feel at ease with OOP.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1343\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-1.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-1.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-1-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-1-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-1-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Level 2: Concurrent and Parallel Programming<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1352\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/multicore.jpg\" alt=\"\" width=\"560\" height=\"315\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/multicore.jpg 560w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/multicore-300x169.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/multicore-200x113.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/multicore-400x225.jpg 400w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>The days of single-core processors are far gone.<\/p>\n<p>Nowadays whether you are buying an off-the-shelf laptop or a high-end server for your business, your processor will definitely have multiple cores.<\/p>\n<p>And sometimes, your program needs to take advantage of these multiple cores to run things in parallel.<\/p>\n<p>This can potentially lead to increased throughput, higher performance, and better responsiveness.<\/p>\n<p>But let me be clear about one thing here.<\/p>\n<p>If high performance and increased throughput are absolutely crucial, Python wouldn&#8217;t be the best language to support parallel programming.<\/p>\n<p>In this situation, I would personally prefer <strong>golang<\/strong> instead (or good old <strong>C<\/strong>).<\/p>\n<p>But since this is an article about Python, let&#8217;s keep our focus on Python.<\/p>\n<p>Before you dive in and write your first parallel program, there are some parallel processing concepts that you should learn about first.<\/p>\n<p>Here are some of these concepts.<\/p>\n<h3>Mutual Exclusion<\/h3>\n<p>When you have some data that is shared across multiple threads or processes, it is important to synchronize access to these shared resources.<\/p>\n<p>If you don&#8217;t, a race condition can happen which might lead to unexpected and sometimes disastrous consequences. I will talk more about race conditions later.<\/p>\n<p>Mutual exclusion means that one thread blocks the further progress of other concurrent threads that require the use of the shared resource.<\/p>\n<h3>Locks<\/h3>\n<p>Locks is one of the various implementations of mutual exclusion.<\/p>\n<p>To understand what locks are, you can think about them from a conceptual perspective.<\/p>\n<p>If a thread wants to access a shared resource, this thread must grab a lock before it&#8217;s granted access to that resource.<\/p>\n<p>And after it&#8217;s done with the resource, it releases this lock.<\/p>\n<p>If the lock is not available because it is grabbed by another thread, then the thread has to wait for the lock to be released first.<\/p>\n<p>This simple concept guarantees that at most one thread can have access to a shared resource at a time.<\/p>\n<h3>Deadlocks<\/h3>\n<p>A deadlock is when your program comes to a complete halt because some of the threads can&#8217;t progress further because they can&#8217;t acquire a lock.<\/p>\n<p>For example, imagine Thread A is waiting on Thread B to release a lock. At the same time, Thread B is waiting on Thread A to release another lock that Thread A is currently holding.<\/p>\n<p>In this dire situation, neither Thread A nor Thread B can progress any further so your program is hosed!<\/p>\n<p>This is what a deadlock is.<\/p>\n<p>And it happens more often than you think.<\/p>\n<p>To make the situation worse, it&#8217;s also one of the hardest problems to debug.<\/p>\n<h3>Race conditions<\/h3>\n<p>As I mentioned earlier, a race condition is a situation that arises when accessing a shared resource isn&#8217;t protected (for example, by locks).<\/p>\n<p>This can lead to disastrous unexpected outcomes.<\/p>\n<p>Take a look at this example.<\/p>\n<pre class=\"prettyprint\"><code>import threading\n# x is a shared value\nx = 0\nCOUNT = 1000000\n\ndef inc():\n    global x\n    for _ in range(COUNT):\n        x += 1\n\ndef dec():\n    global x\n    for _ in range(COUNT):\n        x -= 1\n\nt1 = threading.Thread(target=inc)\nt2 = threading.Thread(target=dec)\nt1.start()\nt2.start()\nt1.join()\nt2.join()\n\nprint(x)<\/code><\/pre>\n<p>Here is what the code above does. There is a shared global variable <span class=\"symbol\">x<\/span> that is initialized to 0.<\/p>\n<p>Two functions <strong>inc<\/strong> and <strong>dec<\/strong> run in parallel. <span class=\"symbol\">inc()<\/span> increments the value of <strong>x<\/strong> 1 million times whereas <span class=\"symbol\">dec()<\/span> decrements the value of <strong>x<\/strong> 1 million times.<\/p>\n<p>By quickly going through the code, it can be concluded that the final value of <strong>x<\/strong> should be 0&#8230; but is it?<\/p>\n<p>Here is what I get when I run the above code.<\/p>\n<pre class=\"prettyprint\"><code> $ python3 race.py\n158120\n $ python3 race.py\n137791\n $ python3 race.py\n-150265\n $ python3 race.py\n715644<\/code><\/pre>\n<p>The reason why this is happening is that the shared resource <strong>x<\/strong> is not protected (by locks for example).<\/p>\n<h3>Python&#8217;s Parallel Programming<\/h3>\n<p>Only after you&#8217;re comfortable with the concepts discussed above that you are ready to learn how to write concurrent programs in Python.<\/p>\n<p>First, you should learn how Python&#8217;s definition of <em>multiprocessing<\/em> is different from <em>multithreading<\/em>. (By the way, <a href=\"https:\/\/www.geeksforgeeks.org\/operarting-system-thread\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">this is completely unrelated to threads and processes from an OS perspective<\/a>).<\/p>\n<p>To understand this distinction between multiprocessing and multithreading from Python&#8217;s view, you will need to learn and understand the <a href=\"https:\/\/realpython.com\/python-gil\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">global interpreter lock<\/a> (GIL).<\/p>\n<p>You will also need to learn about the <a href=\"https:\/\/docs.python.org\/3\/library\/threading.html\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">threading<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/queue.html#module-queue\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">queue<\/a>, and <a href=\"https:\/\/docs.python.org\/3\/library\/multiprocessing.html\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">multiprocessing<\/a>&nbsp;Python modules.<\/p>\n<p>All of these modules provide you with the primitives you need to write parallel programs.<\/p>\n<p><a href=\"https:\/\/www.linuxjournal.com\/content\/multiprocessing-python\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Here is a good article about multiprocessing in Python.<\/a><\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1344\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-2.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-2.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-2-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-2-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-2-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/h2>\n<h2 id=\"level3\">Level 3: Socket Programming<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1354\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/socket-programming.jpg\" alt=\"\" width=\"560\" height=\"315\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/socket-programming.jpg 560w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/socket-programming-300x169.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/socket-programming-200x113.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/socket-programming-400x225.jpg 400w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>By now you should be very comfortable writing Python code that runs on a single machine.<\/p>\n<p>But what if you want to write code that communicates with other machines over a network?<\/p>\n<p>If you want to do that, then you need to learn about <a href=\"https:\/\/realpython.com\/python-sockets\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">socket programming<\/a>.<\/p>\n<p>And for that I highly recommend you learn about the basics of computer networks first.&nbsp;Here&#8217;s&nbsp;<a href=\"https:\/\/amzn.to\/2Wwp7Ns\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">my favorite book<\/a>.<\/p>\n<p>After you learn the basic networking concepts, you can use Python&#8217;s libraries to write code on one machine that communicates with code on another.<\/p>\n<p>It&#8217;s like magic. I still remember the exhilaration I felt the first time I had two laptops communicating back and forth to each other over a Wifi network.<\/p>\n<p>Follow these three steps to get started.<\/p>\n<h3>Step 1: Write an Echo Program<\/h3>\n<p>In this step, you will use <a href=\"https:\/\/docs.python.org\/3\/library\/socket.html\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Python&#8217;s socket module<\/a> to write a simple TCP server on one machine and a TCP client on another.<\/p>\n<p>Make sure they are two different computers and that both of them are connected to your home network.<\/p>\n<p>The idea of the Echo program is simple. The client-side reads a message from the user and sends this message to the server over the network.<\/p>\n<p>At the server-side, when this message is received, the server echoes the same message back to the client.<\/p>\n<p>Think of the <strong>Echo<\/strong> program as the <strong>Hello World<\/strong> program but for socket programming.<\/p>\n<p>After that, you can move on to more complex programs.<\/p>\n<h3>Step 2: Play around with HTTP<\/h3>\n<p>Once you&#8217;re comfortable with writing simple TCP client-server applications, you can start using <a href=\"https:\/\/requests.readthedocs.io\/en\/master\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Python&#8217;s requests module<\/a> to send and receive HTTP messages.<\/p>\n<p>This is especially useful because the vast majority of web services these days provide an HTTP API interface that you can interact with programmatically. For example, <a href=\"https:\/\/developers.facebook.com\/docs\/graph-api\/using-graph-api\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Facebook<\/a>, <a href=\"https:\/\/developer.twitter.com\/en\/docs\/api-reference-index\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Twitter<\/a>, and <a href=\"https:\/\/developers.google.com\/places\/web-service\/search\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Google maps<\/a> all have HTTP API interfaces that your code can communicate with.<\/p>\n<p>And if you feel a little more adventurous and want to take this a bit further, you can also scrape the web with <a href=\"https:\/\/www.crummy.com\/software\/BeautifulSoup\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">BeautifulSoup.<\/a><\/p>\n<h3>Step 3: Know thy tools<\/h3>\n<p>Like any other program, sometimes when you write a networking program, your program will not work from the first attempt.<\/p>\n<p>However, debugging networking programs is a little different than debugging regular programs.<\/p>\n<p>That&#8217;s why you need to equip yourself with the tools necessary to troubleshoot what&#8217;s going on.<\/p>\n<p>Here are some of the most popular networking tools that you will need.<\/p>\n<p><strong><a href=\"https:\/\/www.geeksforgeeks.org\/ping-command-in-linux-with-examples\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">ping<\/a><\/strong>&nbsp;is used to check the connectivity between your machine and another one.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1326\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM.png\" alt=\"\" width=\"1820\" height=\"842\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM.png 1820w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-300x139.png 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-768x355.png 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-1024x474.png 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-200x93.png 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-400x185.png 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-600x278.png 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-800x370.png 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-31-at-2.01.16-PM-1200x555.png 1200w\" sizes=\"(max-width: 1820px) 100vw, 1820px\" \/><\/p>\n<p><strong><a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">netstat<\/a>&nbsp;<\/strong>is a versatile networking tool that allows you to, among other things, monitor network connections both incoming and outgoing.<\/p>\n<p><strong><a href=\"https:\/\/hackertarget.com\/tcpdump-examples\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">tcpdump<\/a><\/strong> is one of my favorite tools for learning networks. It tools allows you to listen to, capture, and analyze real packets going into and out of your computer through any network interface.<\/p>\n<p><strong><a href=\"https:\/\/www.wireshark.org\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Wireshark<\/a><\/strong> is a nice GUI interface that does pretty much everything that&nbsp;<strong>tcpdump<\/strong> can do. I recommend starting out with Wireshark before moving on to tcpdump just because it&#8217;s a little more user-friendly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1327\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot.png\" alt=\"\" width=\"1097\" height=\"619\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot.png 1097w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-300x169.png 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-768x433.png 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-1024x578.png 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-200x113.png 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-400x226.png 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-600x339.png 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Wireshark_screenshot-800x451.png 800w\" sizes=\"(max-width: 1097px) 100vw, 1097px\" \/><\/p>\n<p>And like I said, to understand what all these Get, <span class=\"symbol\">SYN<\/span>, <span class=\"symbol\">SYN ACK<\/span>, <span class=\"symbol\">FIN<\/span> mean you need to <a href=\"https:\/\/amzn.to\/2Wwp7Ns\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">learn networking fundamentals first<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1345\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-3.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-3.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-3-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-3-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-3-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2 id=\"level4\">Level 4: Data Structures and Algorithms in Python<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1356\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph.png\" alt=\"\" width=\"618\" height=\"226\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph.png 618w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph-300x110.png 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph-200x73.png 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph-400x146.png 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/facebook-graph-600x219.png 600w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/p>\n<p>If you reached this level, give yourself a pat on the shoulder.<\/p>\n<p>Because by now, you have the skills that enable you to solve a wide variety of problems.<\/p>\n<p>However, something is missing.<\/p>\n<p>You are still not seasoned enough at writing <strong>efficient<\/strong> code.<\/p>\n<p>What do I mean by that?<\/p>\n<p>For example, you don&#8217;t know how to modify your code to make it run faster. You can&#8217;t even analyze why it is slow in the first place.<\/p>\n<p>This is normal.<\/p>\n<p>The knowledge you have learned so far in the previous levels are not enough for you to have a solid understanding of what performance really is, and how to modify your existing code to make it run faster.<\/p>\n<p>Don&#8217;t believe me? Look at this simple code that calculates the nth <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fibonacci_number\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Fibonacci number<\/a>.<\/p>\n<pre class=\"prettyprint\"><code>def fib(n):\n    if n &lt; 2:\n        return n\n    return fib(n-2) + fib(n-1)\n\nprint(fib(100))<\/code><\/pre>\n<p>The code looks simple enough and very straightforward, right?<\/p>\n<p>Try using this code to calculate&nbsp;<strong>fib(100)<\/strong>&nbsp;[SPOILER ALERT: it will take an extremely long time]<\/p>\n<p>Now let&#8217;s make a simple modification to the code.<\/p>\n<pre class=\"prettyprint\"><code>def fib(n, d):\n    if n &lt; 2:\n        return n\n    if n not in d:\n        d[n] = fib(n-2, d) + fib(n-1, d)\n    return d[n]\n\nprint(fib(100, {}))<\/code><\/pre>\n<p>This time all it took was a few milliseconds and you will get the answer, which is <strong>354224848179261915075<\/strong> just in case you&#8217;re wondering \ud83d\ude42<\/p>\n<p>I used what&#8217;s called <strong>dynamic programming<\/strong> to solve this problem and make it run astronomically faster.<\/p>\n<p>Well, I hope you are convinced by now that you should learn data structures and algorithms.<\/p>\n<p>The skills that you are going to learn at this level are some of the major differentiators between average coders and solid programmers.<\/p>\n<p>You will need to learn about <a href=\"https:\/\/www.geeksforgeeks.org\/data-structures\/linked-list\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">linked lists<\/a>, <a href=\"https:\/\/www.geeksforgeeks.org\/binary-tree-data-structure\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">trees<\/a>, <a href=\"https:\/\/www.geeksforgeeks.org\/stack-data-structure\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">stacks<\/a>, <a href=\"https:\/\/www.geeksforgeeks.org\/queue-data-structure\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">queues<\/a>, <a href=\"https:\/\/www.geeksforgeeks.org\/graph-data-structure-and-algorithms\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">graphs<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hash_table\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">hash tables<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Recursion_(computer_science)\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">recursion<\/a>, <a href=\"https:\/\/www.geeksforgeeks.org\/dynamic-programming\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">dynamic programming<\/a>, searching and sorting algorithms, etc&#8230;<\/p>\n<p>Once you master these concepts, you are steps away from getting a software engineering job at <strong>any<\/strong> tech company of your choice.<\/p>\n<p>I really mean it!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1346\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-1.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-1.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-1-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-1-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-1-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2 id=\"level5\">Level 5: Python Coding Interview Practice<\/h2>\n<p>Congratulations! Now you have what it takes to apply for any software engineering job in any tech company in the whole world.<\/p>\n<p>You only need to pass this dreaded coding interview.<\/p>\n<p>In fact a series of them.<\/p>\n<p>If you are at this level, I have written an in-depth article about <a href=\"https:\/\/www.afternerd.com\/blog\/coding-interview\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">how you can prepare for a coding interview<\/a>.<\/p>\n<p>A typical coding interview will assess your problem-solving skills, communication skills, knowledge of data structures and algorithms, in addition to how good and efficient you are at translating your thoughts into code.<\/p>\n<p>The best way to pass coding interviews is to give yourself an ample amount of time to prepare.<\/p>\n<p>The more you prepare, the better your interview experience will be, and the more likely you will land your dream job.<\/p>\n<p><a href=\"https:\/\/www.leetcode.com\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Leetcode<\/a> is an excellent resource with a ton of coding interview questions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"post-img alignnone wp-image-1282 size-full\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode.png\" alt=\"\" width=\"1894\" height=\"1218\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode.png 1894w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-300x193.png 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-768x494.png 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-1024x659.png 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-460x295.png 460w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-200x129.png 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-400x257.png 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-600x386.png 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-800x514.png 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/leetcode-1200x772.png 1200w\" sizes=\"(max-width: 1894px) 100vw, 1894px\" \/><\/p>\n<p><strong>Leetcode<\/strong> allows you to submit your Python solutions to the coding questions and get instant feedback about the validity and the efficiency of your solutions.<\/p>\n<p>After you start working, you will learn a lot on the job and you will start gaining extensive experience in a very short amount of time.<\/p>\n<p>This is when level 6 starts.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1347\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-6-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2 id=\"level6\">Level 6: Advanced Python<\/h2>\n<p><a href=\"https:\/\/amzn.to\/2WxecDi\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=1491946008&amp;Format=_SL250_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=afternerd-20&amp;language=en_US\" alt=\"\" width=\"190\" height=\"250\" border=\"0\"><\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"https:\/\/ir-na.amazon-adsystem.com\/e\/ir?t=afternerd-20&amp;language=en_US&amp;l=li3&amp;o=1&amp;a=1491946008\" alt=\"\" width=\"1\" height=\"1\" border=\"0\"><\/p>\n<p>If you want to venture into the territory of Python fluency and take your skills to the next level, then <a href=\"https:\/\/amzn.to\/2WxecDi\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">I highly recommend the &#8220;Fluent Python&#8221; book<\/a>.<\/p>\n<p>This book assumes you already have a solid understanding of the basics of Python.<\/p>\n<p>In&nbsp;<em>Fluent Python, <\/em>some of the concepts that you already learned from introductory books&nbsp;are covered from a different angle, in more detail, and with greater depth.<\/p>\n<p>In addition to that, you will learn some new concepts as well.<\/p>\n<p>For example, some of the new concepts that you will learn in this book are<\/p>\n<ol>\n<li><strong>Higher-order Functions<\/strong>: explains how functions can be used as first-class<\/li>\n<li>Thissobjects in Python<\/li>\n<li><strong>Control Flow<\/strong>: covers the topic of generators, context managers, coroutines, and concurrency<\/li>\n<li><strong>Metaprogramming<\/strong>: essentially this is writing code that manipulates code. Some of the topics discussed here are decorators and meta-classes<\/li>\n<\/ol>\n<hr>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1357\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-5.jpg\" alt=\"\" width=\"600\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-5.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-5-300x100.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-5-200x67.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/Level-5-400x133.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/h2>\n<h2>Optional 1: Python Libraries and Frameworks<\/h2>\n<p>Now you have all the basics covered, you are a Python pro.<\/p>\n<p>Well done.<\/p>\n<p>But the journey doesn&#8217;t end here, Python has a ton of useful libraries that can help you even more.<\/p>\n<p>Knowing what libraries to use and when to use them can save you a lot of time and effort and enables you to have the breadth of knowledge that is required to choose the right tools for the right job.<\/p>\n<p>So let&#8217;s talk about some of the most popular Python libraries and frameworks.<\/p>\n<h2>1. Building API services with Python (Flask)<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1296 size-medium\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-300x200.png 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-768x512.png 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-1024x682.png 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-200x133.png 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-400x266.png 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-600x400.png 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM-800x533.png 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/01\/Screen-Shot-2019-01-21-at-4.05.09-PM.png 1174w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>These days, the way large and scalable web applications are built is by creating a bunch of smaller applications that communicate with each other.<\/p>\n<p>This architecture is called a micro-services architecture [buzzword alert] and each of these smaller applications is called a service or micro-service.<\/p>\n<p>These micro-services can communicate in various ways but one of the most popular methods is HTTP.<\/p>\n<p>In other words, each one of these services will expose an HTTP API that other services will be able to talk to.<\/p>\n<p>With that said, it&#8217;s a very good investment to learn how to create API services in Python.<\/p>\n<p>And one of the most popular Python libraries that make this super easy is <a href=\"http:\/\/flask.pocoo.org\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Flask<\/a>.<\/p>\n<p><a href=\"https:\/\/blog.miguelgrinberg.com\/post\/the-flask-mega-tutorial-part-i-hello-world\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Here is a good tutorial about Flask.<\/a><\/p>\n<h2>2. Building Web applications with Django<\/h2>\n<p><a href=\"https:\/\/www.djangoproject.com\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Django<\/a> is a full-fledged web framework that allows you to create an entire web application (both front-end and back-end) in Python.<\/p>\n<p>By learning Django, you will also be introduced to some concepts that are very popular in other web frameworks in other languages like <strong>MVC<\/strong> (model-view-controller) and <strong>ORM<\/strong> (object-relational mapper).<\/p>\n<p><strong>MVC<\/strong> is a way of structuring and organizing your web application whereas <strong>ORM<\/strong> is a technique that bridges the gap between object-oriented programming and accessing data in a database.<\/p>\n<p>And while we&#8217;re at the topic of ORM, It&#8217;s worth mentioning that you should take a look at <a href=\"https:\/\/www.sqlalchemy.org\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">SQLAlchemy<\/a> which is a very popular, and widely-used ORM library in Python.<\/p>\n<p>So roll up your sleeves and go ahead, create your first web application \ud83d\ude42<\/p>\n<h2>3. Machine Learning Libraries<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-475\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2017\/12\/andrewng.jpeg\" alt=\"\" width=\"550\" height=\"304\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2017\/12\/andrewng.jpeg 550w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2017\/12\/andrewng-300x166.jpeg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2017\/12\/andrewng-200x111.jpeg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2017\/12\/andrewng-400x221.jpeg 400w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n<p>Python has become the de-facto language for machine learning and data science.<\/p>\n<p>This comes as no surprise, given the maturity of Python&#8217;s machine learning libraries.<\/p>\n<p>If you want to be a data scientist, I highly recommend learning the mathematical and statistical fundamentals of machine learning first before learning the ML libraries in Python.<\/p>\n<p><em><a href=\"https:\/\/amzn.to\/2UcEyIq\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Introduction to Statistical Learning<\/a>&nbsp;<\/em>is an excellent place to start.<\/p>\n<p>If you prefer a video course instead, then you should take <a href=\"https:\/\/www.coursera.org\/learn\/machine-learning\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">Andrew Ng&#8217;s ML course on Coursera<\/a>.<\/p>\n<p>Once you have the basics covered, start playing around with these Python libraries.<\/p>\n<p><a href=\"https:\/\/scikit-learn.org\/stable\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\"><strong>1- scikit-learn<\/strong><\/a> This library has everything under the sun when it comes to ML algorithms.<\/p>\n<p><a href=\"https:\/\/www.tensorflow.org\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\"><strong>2- Tensorflow<\/strong><\/a> Another very popular open-source machine learning framework.<\/p>\n<p><a href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\"><strong>3- pandas<\/strong><\/a> A popular data analysis library.<\/p>\n<h2>Optional 2: Python Implementation (CPython)<\/h2>\n<p>Python is an interpreted language.<\/p>\n<p>This means that your Python code doesn&#8217;t get compiled down to a machine code directly, but first, it is compiled to an intermediate language, called <strong>byte code<\/strong>, which is later interpreted by another piece of software called <strong>the interpreter<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1365\" src=\"http:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter.jpg\" alt=\"\" width=\"1972\" height=\"780\" srcset=\"https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter.jpg 1972w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-300x119.jpg 300w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-768x304.jpg 768w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-1024x405.jpg 1024w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-200x79.jpg 200w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-400x158.jpg 400w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-600x237.jpg 600w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-800x316.jpg 800w, https:\/\/www.afternerd.com\/blog\/wp-content\/uploads\/2019\/02\/python-interpreter-1200x475.jpg 1200w\" sizes=\"(max-width: 1972px) 100vw, 1972px\" \/><\/p>\n<p>Do you want to see how the <strong>bytecode<\/strong> looks like for a simple <strong>Hello World<\/strong> program?<\/p>\n<p>Let&#8217;s create a source file <strong>helloworld.py<\/strong><\/p>\n<pre class=\"prettyprint\"><code># helloworld.py\nprint(\"hello world\")<\/code><\/pre>\n<p>Here is how to view the <strong>bytecode<\/strong> for the above source code<\/p>\n<pre class=\"prettyprint\"><code>$ python3 -m dis helloworld.py\n2           0 LOAD_NAME                0 (print)\n            2 LOAD_CONST               0 ('hello world')\n            4 CALL_FUNCTION            1\n            6 POP_TOP\n            8 LOAD_CONST               1 (None)\n           10 RETURN_VALUE<\/code><\/pre>\n<p>This <strong>bytecode<\/strong> will then be interpreted by an interpreter. This is when it gets executed and you finally see <strong>hello world<\/strong> printed on your screen.<\/p>\n<p>There are various Python implementations for the compiler and the interpreter.<\/p>\n<p>However,<a href=\"https:\/\/github.com\/python\/cpython\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\"><b> CPython<\/b><\/a>&nbsp;is the default and most widely-used one. It&#8217;s written entirely in C.<\/p>\n<p>It is both an&nbsp;<b>interpreter<\/b>&nbsp;and a <strong>compiler<\/strong> as it compiles&nbsp;Python&nbsp;code into <strong>bytecode<\/strong> and then interprets the bytecode into machine language.<\/p>\n<p><em>So why am I talking about Python implementation?<\/em><\/p>\n<p><em>Do you really need to know this nitty-gritty details of Python to be a Python master?<\/em><\/p>\n<p>Honestly, the answer is no.<\/p>\n<p>But if you are curious about how Python&#8217;s list, tuples, functions,.. etc are implemented, and if you are willing to learn a new language (C) along the way, then maybe you should consider contributing to <strong>CPython<\/strong>.<\/p>\n<p>And if you don&#8217;t know how to get started, then <a href=\"http:\/\/www.pgbovine.net\/cpython-internals.htm\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">I highly recommend Philip Guo&#8217;s 10-hour course on CPython<\/a>.<\/p>\n<h2>Frequently Asked Questions<\/h2>\n<h3>Q: Is it hard to learn Python?<\/h3>\n<p>Hard and easy is relative.<\/p>\n<p>What I can assure you is that learning Python is easier than learning other programming languages like C++, and I love C++ by the way \ud83d\ude42<\/p>\n<p>It is also the case that most universities use Python for their <em>CS 101<\/em> class just because of how easy and fast it is to learn Python.<\/p>\n<h3>Q: How long does it take to learn Python?<\/h3>\n<p>If you are completely new to programming in general, I would give myself 6 months to learn level 0 (the basics) and level 1 (OOP).<\/p>\n<p>If you are already a programmer coming from a different programming language, I would give it two weeks.<\/p>\n<p>Beyond level 1, it is not easy to assess how long it is going to take you because to fully understand the concepts beyond level 1, you also need to learn a lot of CS fundamental concepts that are orthogonal to Python (e.g. Data Structures, Algorithms, Operating Systems, Networking, etc&#8230;)<\/p>\n<h3>Q: I am new to programming, can I learn Python in 24 hours or a week?<\/h3>\n<p>No.<\/p>\n<h3>Q: What can I do with Python?<\/h3>\n<p><a href=\"https:\/\/www.afternerd.com\/blog\/what-is-python-used-for\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">I wrote an article about that<\/a>.<\/p>\n<h3>Q: Should I learn Python 2 or Python 3?<\/h3>\n<p>Python 3.<\/p>\n<p>Python 2 has reached end-of-life and is no longer going to be maintained.<\/p>\n<h3>Q: Do you offer any resources to learn Python?<\/h3>\n<p>Yes. Here are the resources I offer:<\/p>\n<ol>\n<li>This blog <strong><em>afternerd.com<\/em><\/strong><\/li>\n<li><a href=\"https:\/\/www.afternerd.com\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">My newsletter<\/a>.<\/li>\n<li>[New] <a href=\"https:\/\/www.youtube.com\/channel\/UC7AAHgiYvB9ubN8yrtryrkw\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">My YouTube channel<\/a>.<\/li>\n<li>[New] <a href=\"https:\/\/courses.afternerd.com\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-abc=\"true\">My Premium Courses.<\/a><\/li>\n<\/ol>\n<div id=\"x-end\">And in addition to me, there are numerous other resources online.<\/div>\n<h2>Featured Posts<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.afternerd.com\/blog\/learn-python\/\">The Python Learning Path (From Beginner to Mastery)<\/a><\/li>\n<li><a href=\"https:\/\/www.afternerd.com\/blog\/learn-computer-science\/\">Learn Computer Science (From Zero to Hero)<\/a><\/li>\n<li><a href=\"https:\/\/www.afternerd.com\/blog\/coding-interview\/\">Coding Interview Preparation Guide<\/a><\/li>\n<li><a href=\"https:\/\/www.afternerd.com\/blog\/stock-investing-for-beginners\/\">The Programmer&#8217;s Guide to Stock Market Investing<\/a><\/li>\n<li><a href=\"https:\/\/www.afternerd.com\/blog\/start-programming-blog\/\">How to Start Your Programming Blog?<\/a><\/li>\n<\/ul>\n<div class=\"after-post-box\">\n<h2>Are you Beginning your Programming Career?<\/h2>\n<h3>I provide my best content for beginners in the newsletter.<\/h3>\n<ul>\n<li>Python tips for beginners, intermediate, and advanced levels.<\/li>\n<li>CS Career tips and advice.<\/li>\n<li>Special discounts on my premium courses when they launch.<\/li>\n<\/ul>\n<p>And so much more&#8230;<\/p>\n<h3>Subscribe now. It&#8217;s Free.<\/h3>\n<p><script type=\"text\/javascript\" src=\"\/\/mautic.afternerd.com\/form\/generate.js?id=2\"><\/script><\/p>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1364,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[13],"yst_prominent_words":[39,257,1119,336,61,146,147,733,1635,1107,1120,1118,55,1134,64,53,1122,158,1147,1217],"_links":{"self":[{"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/posts\/747"}],"collection":[{"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/comments?post=747"}],"version-history":[{"count":82,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/posts\/747\/revisions"}],"predecessor-version":[{"id":2832,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/posts\/747\/revisions\/2832"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/media\/1364"}],"wp:attachment":[{"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/media?parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/categories?post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/tags?post=747"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.afternerd.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}