Skip to content
On this page

Introduction to Python

This is a beginner's tutorial for Python, featuring the following characteristics:

Free, zero starting point, complete examples, based on the latest version of Python 3.

Python is a computer programming language. You may have heard of many popular programming languages, such as the very difficult-to-learn C language, the widely-used Java language, the beginner-friendly Basic language, and JavaScript for web programming, among others.

So, what kind of language is Python?

First, let's cover some basics about programming languages. Developing programs in any programming language is intended to make computers work, such as downloading an MP3, writing a document, and so on. However, the computer's CPU only understands machine instructions, so despite the significant differences between programming languages, all code ultimately needs to be "translated" into machine instructions that the CPU can execute. Moreover, the amount of code required to perform the same task can vary greatly across different programming languages.

For instance, to accomplish the same task, C might require 1,000 lines of code, Java might need only 100 lines, while Python could do it in just 20 lines.

Thus, Python is considered a high-level language.

You might wonder, is having less code a disadvantage? The trade-off for writing less code is slower execution speed. A C program might run in 1 second, a Java program could take 2 seconds, and a Python program might need 10 seconds.

Does this mean that the lower-level the program, the harder it is to learn, and the higher-level, the easier? Superficially, yes. However, at very high levels of abstract computation, advanced Python programming can also be challenging, so a high-level programming language does not necessarily mean simplicity.

However, for beginners and everyday tasks, Python is very easy to use. Even Google uses Python extensively, so you don't need to worry about learning a language that's not useful.

What can you do with Python? You can perform everyday tasks, such as automatically backing up your MP3 files; create websites—many well-known sites like YouTube are built using Python; or develop backend services for online games, where many games' backend systems are written in Python. In short, Python is versatile and can handle many tasks.

Of course, Python has its limitations, such as writing operating systems, which can only be done in C; developing mobile applications, which requires Swift/Objective-C (for iPhone) or Java (for Android); and creating 3D games, where using C or C++ is preferred.

If you are a complete beginner who meets the following criteria:

  • You know how to use a computer but have never written a program;
  • You remember middle school mathematics and some algebra;
  • You want to go from being a programming novice to a professional software architect;
  • You can dedicate half an hour each day to learning.

Then, don’t hesitate—this tutorial is for you!

History of Python

Python was created by the famous "Uncle Turtle," Guido van Rossum, during Christmas in 1989 to pass the time.

Today, there are about 600 different programming languages in the world, but only about 20 of them are popular. If you have heard of the TIOBE index, you would know the relative popularity of programming languages. Below is a chart showing the top 10 programming languages used over the past few decades:

tiobe.webp

In general, each of these programming languages has its strengths. C is close to the hardware and can be used to write operating systems, making it suitable for programs that require speed and full use of hardware performance. In contrast, Python is a high-level programming language for writing applications.

When you start developing software in any language, you will need many basic ready-made tools to help accelerate the development process, in addition to writing code. For example, if you were to develop an email client, starting from the very bottom by writing network protocol code would take a year or more to complete. High-level programming languages typically offer a well-rounded standard library for tasks such as handling the SMTP protocol for emails or building GUI applications for desktop environments, making it possible to develop an email client in just a few days.

Python offers a comprehensive standard library that covers networking, file handling, GUIs, databases, text processing, and more, often referred to as "batteries included." When developing with Python, many features do not need to be written from scratch; you can use existing libraries directly.

In addition to the built-in libraries, Python has a vast collection of third-party libraries, which are developed by others for you to use directly. If your code is well-encapsulated, it can even become a third-party library for others to use.

Many large websites are built using Python, such as YouTube, Instagram, and Douban in China. Many big companies, including Google, Yahoo, and even NASA, extensively use Python.

Guido positioned Python as "elegant," "explicit," and "simple," so Python programs always appear easy to understand. For beginners, Python is easy to learn, and as you delve deeper, you can write very complex programs.

Overall, Python's philosophy is simplicity and elegance—writing code that is as understandable as possible while using as few lines as necessary. If an experienced programmer boasts about writing obscure code that runs into tens of thousands of lines, you can feel free to laugh at them.

So, what kinds of applications are best suited for Python?

Primarily web applications, including websites, backend services, etc.
Next, everyday utilities, such as scripts for system administrators.
Finally, wrapping programs written in other languages for easier use.

The Drawbacks of Python

Every programming language has drawbacks, and Python is no exception. We've discussed its advantages, so what are Python's disadvantages?

The first drawback is its slow execution speed compared to C programs because Python is an interpreted language, meaning your code is translated into machine code line by line during execution, which is time-consuming. In contrast, C programs are compiled into machine code before execution, making them very fast.

However, many applications do not require such high speeds since users won't notice the difference. For example, developing a web application to download MP3s might take a C program 0.001 seconds to execute, while a Python program might take 0.1 seconds—100 times slower. However, given the network latency of 1 second, would users notice the difference between 1.001 seconds and 1.1 seconds? It's like driving an F1 car or a regular taxi on a congested road; even though the F1's theoretical speed is 400 km/h, if the traffic is moving at 20 km/h, passengers will only feel the 20 km/h speed.

Don’t worry too much about program execution speed.

The second drawback is that the code cannot be encrypted. When distributing Python programs, you are essentially sharing the source code, unlike C, where only the compiled machine code (e.g., a .exe file on Windows) is distributed. It is impossible to reverse-engineer C code from machine code, making it more secure. This issue is limited to cases where your software needs to be sold. The good news is that in today’s internet era, the traditional software licensing business model is declining, while the model of selling services via websites and mobile applications is on the rise, and this newer model does not require sharing source code.

Furthermore, with the ongoing open-source movement aligning with the spirit of a free and open internet, there are countless excellent open-source projects like Linux. We should not overestimate the "commercial value" of our code. Often, big companies are reluctant to open-source their code because it’s poorly written, and if revealed, no one would dare use their products.

Introduction to Python has loaded