What Is Python?
Python is a high-level, general-purpose programming language known for readable syntax and a large ecosystem of libraries. It is widely used for automation, data processing, web development, artificial intelligence, APIs and many other programming tasks.
Python is a programming language
Python is a general-purpose programming language used to express instructions that computers can execute.
It is designed around relatively clear and concise syntax, allowing many programs to be expressed with comparatively little code.
Python can be used for small scripts as well as much larger software systems.
A Python program can be extremely simple
The print() function sends the text to the program's output.
Python source files normally use .py
These files contain Python source code written as plain text.
Python can store values in variables
The variable name provides a way for later instructions to refer to the stored object.
Python has many built-in data types
| Type | Example |
|---|---|
| str | "Hello" |
| int | 42 |
| float | 3.14 |
| bool | True |
| list | [1, 2, 3] |
| dict | {"name": "Tiago"} |
| tuple | (1, 2) |
| set | {1, 2, 3} |
| NoneType | None |
Python is dynamically typed
A variable name does not have to be declared with a fixed type before it is used.
In this example, the name x first refers to an integer and later refers to a string.
The objects still have types. Dynamic typing means Python determines and checks those types at runtime rather than requiring every variable declaration to specify one in advance.
Python can perform calculations
These operators perform addition, subtraction, multiplication, division, exponentiation and remainder operations.
Lists store ordered collections
Python list indexes begin at zero.
Dictionaries store key-value relationships
Individual values can be retrieved using their keys.
Python can make decisions
The program follows different instructions depending on whether the condition is true or false.
Indentation is part of Python syntax
Many programming languages use braces to group blocks of instructions.
Python uses indentation.
The two indented instructions belong to the if block.
Whitespace can therefore affect program meaning. Indentation is not merely visual formatting in Python.
Loops repeat instructions
Output:
range() is useful for repeated operations
This produces:
Functions package reusable behaviour
Output:
Functions help divide larger programs into smaller, reusable pieces.
Python supports object-oriented programming
Classes can define objects that combine data and behaviour.
Programs can be divided into modules
Python code stored in separate files can be imported and reused.
Output:
Python includes a large standard library
A Python installation includes modules for many common programming tasks.
Additional libraries can be installed
Python has a very large ecosystem of third-party packages.
Packages are commonly installed using pip.
The package can then be imported into a Python program.
Projects can use virtual environments
Different projects may depend on different package versions.
A virtual environment creates an isolated Python environment for a project.
Python can read and write files
This makes Python useful for processing large numbers of files automatically.
Python can process CSV data
CSV processing is useful for spreadsheets, exports, reports and data cleaning.
Python works naturally with JSON
Output:
Python can communicate with databases
Python's standard library includes support for SQLite, and third-party packages can connect to many other database systems.
Python can create a SQLite database
Python can communicate with APIs
A Python application can send HTTP requests and process the returned information.
A third-party library such as requests is commonly used for this.
Python is particularly useful for automation
A Python script can perform repetitive technical tasks without someone manually completing each step.
Python can work with Excel files
Libraries such as openpyxl can read, create and modify .xlsx workbooks.
This can automate spreadsheet reporting and data processing.
Python is widely used for data work
Libraries such as NumPy and pandas provide additional tools for numerical and tabular data processing.
Python is widely used in AI and machine learning
Many machine-learning and artificial-intelligence libraries provide Python interfaces.
Python's role here is strengthened by its extensive scientific and data-processing ecosystem.
Python can run web applications
Python can execute on a server and generate website responses.
Python web frameworks include technologies such as Django, Flask and FastAPI.
Python and JavaScript often run in different places
| Python | JavaScript |
|---|---|
| Commonly runs on servers or computers | Runs directly in web browsers |
| Strong data and automation ecosystem | Core language of browser interactivity |
| Can build back-end web services | Can build front-end and back-end applications |
Both languages are general-purpose enough to overlap in many areas.
How does Python code actually run?
The most widely used Python implementation is CPython.
In simplified form, CPython processes source code, compiles it into Python bytecode and executes that bytecode using its interpreter.
Calling Python simply "interpreted" is useful but incomplete. Python implementations can use different execution techniques. CPython normally compiles source code to bytecode before executing it.
Python can also be used interactively
Python provides an interactive environment where instructions can be entered one at a time.
This makes it convenient for experimentation, calculations and testing small pieces of code.
Python emphasises readable syntax
Compare the structure of a simple condition:
Keywords such as if, for, in, def and return make much Python code relatively close to structured written instructions.
What is Python used for?
Automation
Repetitive computer tasks can be scripted.
Data
Files, spreadsheets and databases can be processed.
APIs
Programs can communicate with external services.
Web Development
Python can power server-side web applications.
AI
Python is widely used with machine-learning tools.
Scientific Computing
Numerical and scientific libraries support research and technical computing.
One script can connect several technologies
This ability to connect different formats, systems and services is one reason Python is particularly useful for automation and data-management work.
The simplest way to think about Python
Python provides a language for describing the operations a computer should perform.
Instructions become automation.
Python is a high-level, general-purpose programming language with readable syntax and a large software ecosystem. It can work with files, spreadsheets, databases, APIs and websites, and is widely used for automation, data processing, scientific computing, artificial intelligence and software development.