What is Python? Overview of the Language
Python is a modern, interpreted, high-level programming language, known for its clear and readable syntax. It is ideal for beginners but powerful enough for complex projects. Python is used in web development, automation, artificial intelligence, data analysis, games, desktop applications, and much more.
- Python is open-source - free and with publicly available source code.
- It is cross-platform - runs on Windows, macOS, and Linux.
- It has a huge community and thousands of libraries that make your work easier.
- Used by major companies like Google, NASA, Netflix, Instagram.
Why choose Python?
Python is the ideal choice for beginners due to its simplicity. Unlike other languages that require strict syntax, Python allows writing clear and concise code. Here are some reasons why it is so popular:
- Code is easy to read and write - almost like English.
- You can quickly create prototypes and functional applications.
- It is versatile - from simple scripts to enterprise applications.
- Excellent support for machine learning, AI, and data science.
Example - Python vs. another language
# Python
print("Hello, world!") # Output: Hello, world!
# Java (for comparison)
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
- In Python, you don’t need braces, semicolons, or classes to write a simple program.
- Indentation (spaces at the start of a line) is mandatory and part of the syntax.
Where is Python used?
Python is used in a wide range of fields. Here are some examples:
- Web development - with frameworks like Django and Flask
- Automation - scripts that save time and effort
- Data Science - data analysis, visualizations, statistics
- Machine Learning & AI - using libraries like TensorFlow, PyTorch
- Desktop applications - with PyQt, Tkinter
- Games - with Pygame
Example - simple automation script
# Script that renames files in a folder
import os
folder = "images"
for index, filename in enumerate(os.listdir(folder)):
new_name = f"image_{index + 1}.jpg"
os.rename(os.path.join(folder, filename), os.path.join(folder, new_name))
print("Files have been renamed.")
This example shows how easily you can automate a repetitive task with just a few lines of code.
History and evolution of Python
Python was created in the late 1980s by Guido van Rossum, a Dutch programmer working at the Centrum Wiskunde & Informatica (CWI) in Amsterdam. His goal was to create a programming language that was easy to read, intuitive, and suitable for automation and rapid prototyping.
- The name “Python” does not come from the snake, but from the British comedy troupe Monty Python.
- Guido van Rossum was nicknamed the “Benevolent Dictator For Life” (BDFL) of the language until 2018.
Key milestones in Python's evolution
- 1991 - Official release of
Python 1.0 - 2000 -
Python 2.0introduced, with support for garbage collection and list comprehensions - 2008 - Release of
Python 3.0, a version incompatible with Python 2, but much cleaner and modern - 2020+ - Versions like
3.9,3.10,3.11bring advanced features such as pattern matching, structural typing, and improved performance
Example - Python 2 vs Python 3 code
# Python 2
print "Hello, world!" # worked without parentheses
# Python 3
print("Hello, world!") # correct syntax in modern versions
Python today
Today, Python is one of the most popular programming languages in the world. It is used in education, industry, research, and development. Its popularity is largely due to its simplicity, versatility, and active community.
- It is the #1 language in Data Science and Machine Learning
- Taught in schools and universities as a core language
- Supported by organizations such as the Python Software Foundation
Example - using a modern library
# Using the 'requests' library to make an HTTP call
import requests
r = requests.get("https://api.github.com")
print(r.status_code) # Displays: 200
This example shows how easy it is to interact with web services using modern Python libraries.
Installing and Configuring Python
Python is easy to install on any operating system. Below are the steps for Windows, macOS, and Linux.
Installation on Windows
- Go to python.org/downloads/windows
- Download the latest stable version (usually Python 3.x)
- Run the .exe file and check the “Add Python to PATH” option before clicking “Install”
After installation, open Command Prompt and type python --version to verify
the installation.
Installation on macOS
- Open Terminal
- Install Homebrew (if not installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Install Python:
brew install python
Check installation with python3 --version. macOS comes with an older Python 2
version, so use python3 for the new version.
Installation on Linux (Ubuntu/Debian)
- Open Terminal
- Update packages:
sudo apt update - Install Python:
sudo apt install python3
Check installation with python3 --version. To install pip (package manager):
sudo apt install python3-pip
Configuring the working environment
For more complex projects, it is recommended to use a virtual environment to isolate packages and dependencies.
Creating a virtual environment
# Create a virtual environment
python -m venv myenv
# Activate it
# Windows
myenv\Scripts\activate
# macOS/Linux
source myenv/bin/activate
After activation, you can install packages using pip install without affecting
the global system.
Recommended Editor: VS Code
For writing and running Python code, Visual Studio Code is an excellent choice:
- Free and open-source
- Supports extensions (Python, Jupyter, Git, etc.)
- Integration with terminal and IntelliSense
First Program: “Hello World!”
In any programming language, the first step is to write a program that displays a simple message on the screen. In Python, this traditional program is called “Hello, World!” and is extremely simple.
Example - Hello World in Python
print("Hello, world!") # Output: Hello, world!
- The
print()function is used to display text in the console. - Text can be written in double quotes
" "or single quotes' '. - No semicolon is needed at the end of the line - Python does not require it.
Example - Hello World with a variable
message = "Hello, world!"
print(message) # Output: Hello, world!
This example shows how to store text in a variable and then display it. It is the first step towards writing more complex programs.
Using the Interpreter vs. .py Files
Python can be used in two main ways: directly in the interpreter or via .py files. Each method has its advantages.
Python Interpreter
The interpreter is an interactive interface where you can write and execute code line by line. It is ideal for quick testing and learning.
# Open the terminal and type:
python
# You will see the prompt:
>>>
# Type:
print("Test") # Output: Test
- Fast and interactive
- Ideal for testing expressions and functions
- No saved files needed
.py Files
Python files have the .py extension and can contain structured code, functions, classes, and
modules. They are used for real projects.
# Create a file named hello.py
# File contents:
print("Hello from file!")
# Run it from terminal:
python hello.py
- You can save and reuse code
- Ideal for larger projects
- You can organize code into modules and functions
Recommendation: start with the interpreter for quick testing, then move to .py files for organization and scalability.
