Web Development
HTML Course
CSS Course
JavaScript Course
PHP Course
Python Course
SQL Course
SEO Course

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.

Important to know:
  • 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:

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!");
  }
}
Note:
  • 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:

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.

Fun fact:
  • 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

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.

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

  1. Go to python.org/downloads/windows
  2. Download the latest stable version (usually Python 3.x)
  3. 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

  1. Open Terminal
  2. Install Homebrew (if not installed): /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. 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)

  1. Open Terminal
  2. Update packages: sudo apt update
  3. 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:

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!
Important to know:
  • 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
Advantages:
  • 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
Advantages:
  • 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.

Top