What Is Python and What Is It Used For?

    Lucero del Alba

    In this article, we’ll explain what Python is, what it can be used for, and why it’s so popular.

    1. An Introduction to Python
    2. What Python Is Used For
    3. Why Should You Learn Python Coding?
    4. Why Is Python So Popular?
    5. Six Useful Python Tips
    6. Final Thoughts

    There’s an easy answer to the question of “What Is Python?”, which you could find on the first paragraph of its Wikipedia entry. But it won’t tell you why Python consistently ranks as one of the most popular programming languages, or why it can be used for so many different things, and why it’s so darn good at pretty much all of them.

    The Python logo

    But we want to answer those questions, so let’s take a quick dive and explore what makes Python so unique, popular, and fun.

    An Introduction to Python

    XKCD #353. I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you.

    XKCD #353, “Python”

    In a nutshell, Python is a high-level programming language that was created in 1991 by Guido van Rossum. It has since been released under an open-source license, making it freely available to anyone who’d like to use or modify the software.

    Python is known for its ease of use, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.

    Python Enhancement Proposals (PEPs)

    One feature of Python that sets it apart from other programming languages is the inclusion of what are called “Python Enhancement Proposals” (PEPs). PEPs are documents that describe proposed changes to the language and provide a mechanism for community input on those proposals. Any member of the community can submit a PEP, which then goes through a process of discussion and refinement before being accepted or rejected by the core developers of Python.

    This process ensures that new features added to the language are well-designed and have broad support within the community before being included in the main body of code for Python.

    The Zen of Python

    One such PEP is now legendary: “PEP 20 – The Zen of Python“, written by CPython core developer (the reference implementation of Python) Tim Peters.

    The Zen of Python provides guidance on the design of the language and its associated libraries, stressing the importance of beauty, simplicity, and explicitness:

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!

    The Pythonistas, the “Pythonic Way”, and the Benevolent Dictator for Life

    One of the most common questions asked by new Python programmers is “What is the ‘Pythonic Way’ to do X?” This usually refers to a particular way of solving a problem that makes use of the language’s features in a particularly elegant or efficient manner.

    And while often there are multiple ways to accomplish any given task in Python, experienced Pythonistas often have strong opinions on what constitutes good code, and they’re not shy about sharing those opinions! As Guido van Rossum, Python’s benevolent dictator for life (BDFL), famously said: “there’s only one way to do it, and that’s why it works”.

    What Python Is Used For

    Now we’ll look at the kinds of things Python is typically used for.

    Web Development

    Python is often used for web development. Popular Python web frameworks include Django and Flask, and many large sites including Reddit and Instagram are built using Python.

    Machine Learning and Artificial Intelligence

    Python is super popular for machine learning and artificial intelligence in general, with packages such as TensorFlow and scikit-learn providing powerful tools for these purposes.

    Also, many other popular machine learning libraries, such as Keras and PyTorch, are written in Python.

    Data Science and Data Analysis

    Python is also prominently used in data science and data analysis. The pandas library provides powerful tools for working with tabular data, and the matplotlib library is a popular tool for creating visualizations of that data.

    Jupyter, the notebook environment for Python, is also commonly used by data scientists for exploratory analysis and creating reproducible research.

    Software Testing

    Python is widely used in software testing. The unittest module is a built-in library that provides tools for this purpose, and the pytest framework is a popular third-party alternative to unittest. (Check out An Introduction to Python Unit Testing with unittest and pytest for more on these.)

    Game Development

    Python is also used in game development, with packages such as PyGame providing functionality for creating games and other graphical applications, and it’s also often used for scripting within larger game engines such as Unity (docs and Unreal Engine 4 (docs).

    Why Should You Learn Python Coding?

    Let’s look at reasons why you should consider learning to code in Python.

    Screenshot of Python code

    Python is Easy to Use

    Python is considered one of the easiest languages to learn. This is because Python code is very simple to read and follow, and it can be written in fewer lines than other languages. The language has a concise syntax that allows programmers to express concepts in fewer lines of code than would be possible in other languages. This means that newbies can quickly get up to speed with the basics of coding in Python, and experienced coders can save time by writing more efficient code.

    But even though Python is easy to learn, be assured that it’s also powerful enough to build professional-grade applications.

    Python Is Open-source

    Anyone can contribute to the development of Python, and there are no licensing fees associated with using or developing in this language.

    This also means that there’s a huge community of developers who are willing to help newbies get started, and who are always working on improving the language. And because it’s open-source, you can be sure that there will always be free tools and libraries available for use with Python.

    Why Is Python So Popular?

    Python is so versatile that it can be used for developing both desktop and web applications. It’s easy to learn for beginners and has powerful libraries for data analysis and machine learning.

    Actually, let’s quickly review some of its key features:

    • Object-oriented: code can be organized into classes and modules. This makes it easy to reuse code and create new libraries.
    • Interpreted: Python doesn’t need to be compiled before it’s run. This makes development faster and easier, as you don’t need to wait for the compilation process to finish every time you make a change.
    • High level: Python abstracts away many of the details of implementation (such as memory management) so that programmers can focus on the bigger picture.
    • Dynamic: variables can be created and destroyed at runtime. This makes development faster, as you don’t need to declare variables in advance.
    • Multi-paradigm: including functional, procedural, and object-oriented. This makes it easy to switch between different styles of programming depending on the task at hand.
    • Portable: Python code can be run on any platform that supports the interpreter, making it easy to port code from one platform to another.

    Six Useful Python Tips

    Let’s look at some tips for getting the best out of Python.

    1. Use proper indentation

    Python is very particular about indentation. All lines of code that should be run together must be indented the same amount, or Python will give you an error. This can be four spaces, or one tab, but whatever you choose, be consistent!

    2. Don’t forget the colons

    After declaring a for loop or an if statement, don’t forget to put a colon at the end of the line! Otherwise Python will give you an error.

    3. Use proper grammar in your variable names

    This might seem like a nit-picky rule, but it actually makes your code much easier to read for other people (and for yourself, when you come back to it later!). Stick to using lowercase letters and underscores (_) in your variable names, and try to make them descriptive of what the variable is storing.

    4. Use the built-in help function

    Python has a lot of functions and methods (pre-written code that you can call on to do certain tasks), and it can be overwhelming to try to remember all of them. That’s what the help function is for! If you ever forget how a certain function works, or what arguments it takes, just type help(function_name) in your Python shell.

    5. Use and abuse the standard library

    The standard library is a set of modules that are included with every new installation of Python. These modules provide a ton of functionality, and there’s a good chance that whatever you’re trying to do has already been implemented in the standard library.

    6. Join the community

    There are many ways to get involved in the community, whether it’s through reporting bugs or contributing new features via pull requests on GitHub, answering questions on Stack Overflow, or giving talks at conferences and meetups around the world.

    Final Thoughts

    Python deserves every bit of the attention that it gets. It’s a versatile language that you can use for developing desktop GUI applications and websites. You can also use Python for developing complex scientific and numeric applications. Python is designed with features to facilitate data analysis and visualization.

    And I’ll say it again: not only will getting involved will make you better at Python (because you’ll learn from other people), but it will also help make Python better for everyone else!

    Ready to dive deeper? Here you have some Python courses on SitePoint: