What is Python: the major features and what it’s used for

Python is a computer programming language. Or, in other words, a vocabulary and set of grammatical rules for instructing a computer to perform tasks. Guido van Rossum named it after the BBC television show ‘Monty Python’s Flying Circus.’ Hence, you’ll find that Python books, code examples, and documentation sometimes contain references to this television show.

What is Python used for?

People use Python in many places. Its rich base library makes it excellent for all kinds of little helper scripts. But it scales just as well to large systems. To illustrate: the original creators of YouTube used Python for the most part! Dropbox, as far as I know, is primarily written in Python as well.

You can use Python to automate tasks, perform calculations, create user interfaces, create website backends, access databases, download information from the Internet, etc. It’s a versatile language that is easy to learn and write. It’s perfect for beginning programmers but is just as useful and powerful for seasoned professionals.

Another quickly growing field of expertise is called data science. Many data scientists use Python for their day-to-day work. And these are just a few examples. If you start looking closely, Python is very ubiquitous.

Many people say that Python comes with batteries included. It’s a fun way of stating that it includes a comprehensive base library. In addition to this, you can find hundreds of thousands of external packages contributed by the enormous community. You’ll find supporting base libraries and packages for pretty much anything you want to accomplish.

What are Python’s major features?

It’s is easy to read and write

One of Python’s most notable features is the way it enforces the use of indentation for readability. Without proper indentation, your code won’t even run. In Python, we need to indent all code blocks to the same level. Here’s an example of this at work. If you don’t understand the code yet, don’t worry:

def bigger_than_five(x):
  # The contents of a function are indented
  if x > 5:
    # This is another, even more indented block of code
    print("X is bigger than five")
    # And one more!
    print("x is 5 or smaller")

Because indentation is required, the Python language does not need curly braces to group code blocks like Java, C, and C#. Although it’s a subjective matter, people generally agree that it makes Python easier on the eyes.

Interpreted vs compiled

Python is Interpreted

Python code is interpreted on the fly by the Python interpreter when you run a program. This is true for CPython, which is the reference implementation of the Python programming language. Being an interpreted language means that the Python interpreter opens the file and starts reading it line by line, performing the appropriate actions for each statement. For example, when the Python interpreter encounters the function call print("Hello") in your code, it will take the provided string and feed it to some internal function that will print the text to your screen.

Compiled languages

Interpretation is a totally different approach than compiled languages like C, in which code compiles into low-level machine code that can be run directly by the computer’s processor. Compiling code like this is also called ahead-of-time compilation (AOT).

Because no interpreter is acting as an intermediary, there’s no overhead. So, in theory, compiled code is much faster. In practice, however, using the right algorithms and writing efficient code can make a lot of difference. In addition, many popular Python libraries like Numpy contain C-based code at their core, making them extremely fast while you still profit from all the good things Python has to offer.

Advantages of interpreted languages

An interpreted language has several advantages compared to ahead-of-time compilation:

  • You can write your code in a text editor and execute it directly. No additional steps like compilation and linking are necessary.
  • Because it’s plain text, you can simply open a program and inspect its contents. In contrast, compiled code is not human readable.
  • It is platform-independent. As long as the platform has a Python interpreter, your code will work. Compiled code ties itself to a specific platform, like Windows and Linux, and specific processor architecture, like Intel or ARM.

Some of these advantages can also be a disadvantage. As already mentioned, interpreted languages are not high-performance languages. Also, the fact that the source code is easy to read and modify is not an advantage to vendors that want to protect their copyright.

Between interpreted and compiled

An in-between option is a just-in-time compiler (JIT). With JIT, you compile your code while running the program. JIT tries to combine the speed advantage of ahead-of-time compilation with the flexibility of interpretation. A big advantage of JIT is that the JIT compiler keeps optimizing your code, even while it is running. The longer your code runs, the more optimized it will become.

Java and the .NET framework are notable examples of JIT compilation, but a JIT-based Python implementation also exists, called PyPy. This project has come a long way and is usable as a drop-in replacement in many cases. See the chapter on Python concurrency for more information on PyPy.

Dynamically typed

Another advantage of interpreted languages is that it opens the door to dynamic typing. What does that mean? I’ll demonstrate it with some simple code.

Here are a few variable declarations in Java:

String myName = "Erik";
int myAge = 37;
float mySalary = 1250.70;

In a strongly typed language, you need to specify the exact type of each variable, like Stringint, and float. It gets even uglier when objects are involved.

Now let’s look at Python variables. In Python, we can do exactly the same without types:

my_name = "Erik"
my_age = 37
my_salary = 1250.70

As you can see, the Python variant is a lot cleaner and easier on the eyes!

When running this code, Python dynamically finds out the type of our variables. Say, for example, I’d like to know my yearly income by multiplying my salary by 12. I’d need to do the following:

my_income = my_salary * 12

Python will look at my_salary, see that it is a floating-point value, and perform the math. If my_salary would have been a string, Python wouldn’t complain though. It would detect it’s a string and just create a new one, consisting of 12 repetitions of that string! Java, however, would fail with an error in such cases.

Dynamic typing has many advantages. In general, it makes it easier to get started quickly. Some will tell you that it’s more error-prone. A strongly typed language like Java won’t compile when there’s a type error. Python will probably continue running, but the output will be unexpected. It is my experience that it doesn’t happen that often. In addition, you’ll find out soon enough during testing and fix the error before the software ever goes to production.

Since Python version 3.5, Python also supports type hints. It’s an optional feature, but many programmers embrace it since it has quite a few advantages, like better auto-completion in your Python IDE.

Garbage collection

Python has the concept of variables. A variable allows you to store any value like a number, a string of text, or even bigger objects.

Each variable you declare takes up space in your computer’s memory. This can add up quickly, especially when you create programs that run for a long time. So you need a way to clean up variables that you don’t use anymore.

In some languages, you need to perform this cleanup explicitly. This is prone to a type of error called a memory leak. If you make a little mistake and forget to clean up, your software will slowly eat up available memory. Lucky for us, Python’s garbage collector takes care of cleaning up unused variables automatically!

I’m not going into the nitty-gritty details here, but you can rest assured Python will do a perfect job, and it will never accidentally clean up a variable that you still need.

What is Python’s popularity?

Python comes in second place on a well-known list of popular programming languages since January 2021. Javascript, due to its stronghold as a web development language, is still number one, though. This popularity is a great advantage. There are vast amounts of resources, sample code, and help available. Python is here to stay; learning it is a safe bet!

About the author

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He's been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python!

4 thoughts on “What is Python: the major features and what it’s used for”

  1. my name is Anthony Copeland trying to learn Python and like to build an multiple choice
    quiz game that will add up the correct answers and restart when finished. I’m just starting out and hope to learn how to program in Python when I finished going through this tutorial.


  2. Great job!
    But not all your readers are native English speakers. And even google translate does not know what have your meant with “the Python language does not need ACCOLADES to group blocks of code like Java, …”
    Thanks for your efforts anyway!

Leave a Comment