The best way to learn Python ( 2021)

Introduction

Python is a very popular language. It is also one of the languages ​​that are suitable for beginners. The best way to learn Python is to get an overview of everything you need to know about Python.
In this article, we will divide the Python learning process into 4 levels. Each level contains a set of tips that are needed at the next level.

Python learning steps

Level 0: Beginners

Python and learning Python You are a complete beginner, this level will be your starting point. A beginner is someone who has not previously coded in Python or any other programming language. If you are familiar with a different programming language, you should go to level.

At this level, most of the concepts you will learn are general programming concepts. Basic skills you need to be a programmer. This means that these concepts are not unique to Python; They can also be used in other programming languages.
Some of these basic concepts are variables, data types, operations, functions, conditions, and loops.

Variables

Variables are basically stored for your application data. In fact, it’s a way of naming data for later use. Consider the following example:

In this example, we define a msg variable that stores the Hello World value! This allows us to later print Hello World using only the name of the variable that stores this value (instead of typing Hello World).

Data types in Python

We referred to variables as data storage. Now let’s talk about data. In Python, there are many different types of data. For example, in the snippet code above, there is a special type of data such as Hello World that Python (and other programming languages) call string.
A string is a sequence of characters. But strings are not the only data type in Python; There are also integers, floating numbers, lists and dictionaries. By the end of Level., You need to know this type of data and understand how to use it in your application.

Operation

Operations are actually how to manipulate and change data in applications. In other words, your programs must work on the data and generate more data until the final result is reached. You also work on data.
In Python and all programming languages, there is minimal arithmetic, comparison and logic operations.

Conditions

To write any program, you will always need the ability to review the situation and change the behavior of the program according to the situation. Conditional expressions give you the ability to use “if”, “otherwise”, or otherwise. Here is an example of if-other expressions in Python.

blank

Functions

A function is a code set in Python that is executed only when called. You can pass parameters as input to a function, and the function can return data as output. In Python, they define a function using the def keyword.
Here is an example of a hello world program using a say_hello function:

blank

These are just some of the goal-setting shareware that you can use. But most importantly, what you need to master this level is to use the above concepts to solve problems. You will never become a good programmer if you just read books and take courses.
This level not only represents the basis of the concepts of mastering Python but also mastering any other programming language. Do not cross easily after that.

 

Level 1: Object Oriented Programming

blank
Object Oriented Programming

Everything in Python is an object. What exactly is an object?
There are different methods, models or patterns for writing computer programs. One of the most popular programming methods is called Object-Oriented Programming (OOP). In object-oriented programming, an object refers to a specific instance of a class; And the class is like a map of the situation and actions that an object can do. In Python, for example, “Person Class” might be something like this.

blank

The upper class describes each person’s situation and actions. For example, each person will have a name and age. These two contexts are what determines the state of the object. In OOP terms, the name and age are called “object attributes”.
To learn OOP in Python, you have to go through several steps.

Step 1: Learn the concepts of OOP

As mentioned earlier, OOP is a programming template, a way to build and design your code. OOP concepts are not limited to Python; So the concepts you learn will easily apply to any other programming language.

Step 2: Learn about Python classes and objects

At this stage, you should apply the abstract concepts you learned in the previous step specifically to Python. Examine the properties and methods of the created objects.

Step 3: Solve Python problems using OOP

This is an important step. In this step, learn how to use OOP to design and build your code. In fact, this stage is more of an art than a science. This means that the only way to get better is to practice, practice and practice more.
Use Python again to solve more problems, but try to structure your solutions in an object-oriented way. The more you practice, the more professional you will be.

Level 2: Simultaneous and parallel programming

blank

Python learning and the Python learning process of single-core processors are over. Whether you buy a regular laptop or a high-end server for your business today, your processor definitely has multiple cores. And sometimes, your application has to use these multiple cores to run things in parallel. This can potentially lead to increased throughput, higher performance and better responsiveness.
But if high performance and increased throughput are important, Python will not be the best language to support parallel programming. In this case, we recommend golang instead.
But since this article is about Python, let’s focus on Python. Before writing your first parallel program, there are several concepts of parallel processing that you must first learn. Here are some of the concepts.

Mutual monopoly

Synchronizing access to these shared resources is important when sharing data across multiple topics. Cross-monopoly is an algorithm used in parallel programming to prevent the simultaneous use of shared resources such as global variables by a piece of computer code called the critical part.

Locks

Locking is one of the implementations of reciprocal monopoly. To understand what a lock is, you can look at it from a conceptual perspective. If a string wants to access a shared resource, it must lock before accessing that resource.
And when you work with this source, it releases this lock. If the lock is not available due to being occupied by another string, the string must wait for the lock to be released. This simple concept ensures that a maximum of one string can access a shared resource.

Deadlocks

Deadlock occurs when your program stops; Because some disciplines can not progress due to failure to lock.
For example, suppose that string A waits for string B to release a lock; At the same time, string B is waiting for string A to release a lock. In this dire situation, neither A nor B can progress. This is the impasse and it happens more than you think. Debugging it is also one of the most difficult problems.

Competitive status (Race condition)

A competitive situation is a defect in a computer system in which the outcome of the output unexpectedly depends on the timing and sequence of other events. The term is basically a condition in which two signals compete with each other to affect the output sooner.
Only after you are familiar with the above concepts can you learn how to write parallel programs in Python.

 

 

 

blank
Socket Programming

Level 3: Socket Programming

Learning Python and the steps of learning Python
What if you want to write code that communicates with other devices over the network?
If you want to do this, then you need to learn about socket programming. You can use Python libraries to write code on one device that communicates with code on another device.
Follow these three steps to get started:

Step 1: Write an Echo program

In this step, use the Python socket module to write a simple TCP server on one device and client TCP on another. Make sure both computers are connected to your home network. The idea of ​​the Echo app is simple. The client side reads a message from the user and sends this message to the server over the network.
On the server side, when this message is received, the server sends the same message to the client. Consider Echo like Hello World but for socket programming. You can then move on to more complex applications.

Step 2: Play with HTTP

Once you’ve written your TCP program, you can use the Python Request module to send and receive HTTP messages.
This is very useful because most web services these days offer an HTTP API interface that you can use to communicate with the application. For example, Facebook, Twitter, and Google Maps all have HTTP APIs that your code can communicate with.

 

Step 3: Know your tools

Like any other program, sometimes your first attempt will not succeed when writing a network program. However, debugging in network applications is a little different from debugging in regular applications. That’s why you need to equip yourself with the tools you need to troubleshoot what’s going on. Here are some of the most popular networking tools you need.
ping is used to check the connection between your device and another device.

netstat is a versatile networking tool that lets you monitor network connections on input and output.
tcpdump lets you record and analyze real packets entering or leaving your computer through any network interface.
Wireshark is a good graphical user interface that does almost everything tcpdump can do. We recommend that you start with Wireshark before working with tcpdump as it is more user-friendly.

At this stage you should learn linked lists, trees, stacks, queues, graphs, hash tables, recursion, dynamic programming, searching and sorting algorithms.

By going through these Python learning steps, you are ready to run various tasks in Python. The more you learn and practice about object-oriented programming, Python algorithms, concurrent and parallel programming, the more professional you will become.

Leave a Reply

Your email address will not be published. Required fields are marked *