Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, September 21, 2026

What Is Python?

// programming

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.

// definition

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.

// hello world

A Python program can be extremely simple

print("Hello, world!")

The print() function sends the text to the program's output.

Hello, world!
// files

Python source files normally use .py

hello.py automation.py data_cleaner.py api_client.py

These files contain Python source code written as plain text.

// variables

Python can store values in variables

name = "Freelance Coder" price = 25.50 quantity = 4 active = True

The variable name provides a way for later instructions to refer to the stored object.

// data types

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
// dynamic typing

Python is dynamically typed

A variable name does not have to be declared with a fixed type before it is used.

x = 10 x = "hello"

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.

// operators

Python can perform calculations

a = 10 b = 3 a + b a - b a * b a / b a ** b a % b

These operators perform addition, subtraction, multiplication, division, exponentiation and remainder operations.

// lists

Lists store ordered collections

languages = [ "Python", "JavaScript", "PHP" ]

Python list indexes begin at zero.

languages[0] # "Python"
// dictionaries

Dictionaries store key-value relationships

product = { "name": "Keyboard", "price": 39.99, "stock": 12 }

Individual values can be retrieved using their keys.

product["price"] # 39.99
// conditions

Python can make decisions

age = 20 if age >= 18: print("Adult") else: print("Under 18")

The program follows different instructions depending on whether the condition is true or false.

// indentation

Indentation is part of Python syntax

Many programming languages use braces to group blocks of instructions.

Python uses indentation.

if temperature > 20: print("Warm") print("Open the window") print("Finished")

The two indented instructions belong to the if block.

Whitespace can therefore affect program meaning. Indentation is not merely visual formatting in Python.

// loops

Loops repeat instructions

for number in [1, 2, 3]: print(number)

Output:

1 2 3
// range

range() is useful for repeated operations

for i in range(5): print(i)

This produces:

0 1 2 3 4
// functions

Functions package reusable behaviour

def add(a, b): return a + b result = add(5, 7) print(result)

Output:

12

Functions help divide larger programs into smaller, reusable pieces.

// classes

Python supports object-oriented programming

class Product: def __init__(self, name, price): self.name = name self.price = price product = Product( "Keyboard", 39.99 )

Classes can define objects that combine data and behaviour.

// modules

Programs can be divided into modules

Python code stored in separate files can be imported and reused.

import math result = math.sqrt(25) print(result)

Output:

5.0
// standard library

Python includes a large standard library

A Python installation includes modules for many common programming tasks.

Files JSON CSV SQLite Dates Regular Expressions Networking ZIP Files
// packages

Additional libraries can be installed

Python has a very large ecosystem of third-party packages.

Packages are commonly installed using pip.

pip install requests

The package can then be imported into a Python program.

import requests
// environments

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 -m venv .venv
Project A ↓ Environment A ↓ Its packages Project B ↓ Environment B ↓ Different packages
// file handling

Python can read and write files

with open( "example.txt", "r", encoding="utf-8" ) as file: text = file.read() print(text)

This makes Python useful for processing large numbers of files automatically.

// csv

Python can process CSV data

import csv with open( "customers.csv", encoding="utf-8", newline="" ) as file: rows = csv.reader(file) for row in rows: print(row)

CSV processing is useful for spreadsheets, exports, reports and data cleaning.

// json

Python works naturally with JSON

import json text = '{"name": "Alice", "active": true}' data = json.loads(text) print(data["name"])

Output:

Alice
// databases

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 ↓ SQL ↓ Database ↓ Rows of data
SQLite PostgreSQL MySQL SQL Server
// sqlite example

Python can create a SQLite database

import sqlite3 connection = sqlite3.connect( "products.db" ) cursor = connection.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS products ( id INTEGER PRIMARY KEY, name TEXT, price REAL ) """) connection.commit() connection.close()
// apis

Python can communicate with APIs

A Python application can send HTTP requests and process the returned information.

Python program ↓ HTTP request ↓ API ↓ JSON response ↓ Python data

A third-party library such as requests is commonly used for this.

import requests response = requests.get( "https://api.example.com/products" ) data = response.json()
// automation

Python is particularly useful for automation

A Python script can perform repetitive technical tasks without someone manually completing each step.

Read files ↓ Clean data ↓ Call API ↓ Update database ↓ Create spreadsheet ↓ Generate report
// spreadsheets

Python can work with Excel files

Libraries such as openpyxl can read, create and modify .xlsx workbooks.

from openpyxl import Workbook workbook = Workbook() sheet = workbook.active sheet["A1"] = "Product" sheet["B1"] = "Price" workbook.save( "products.xlsx" )

This can automate spreadsheet reporting and data processing.

// data

Python is widely used for data work

Data Cleaning Data Analysis Statistics Visualisation Spreadsheets Databases

Libraries such as NumPy and pandas provide additional tools for numerical and tabular data processing.

// artificial intelligence

Python is widely used in AI and machine learning

Many machine-learning and artificial-intelligence libraries provide Python interfaces.

Machine Learning Neural Networks Natural Language Processing Computer Vision

Python's role here is strengthened by its extensive scientific and data-processing ecosystem.

// web development

Python can run web applications

Python can execute on a server and generate website responses.

Browser ↓ HTTP request ↓ Python web application ↓ Database / APIs ↓ HTTP response ↓ Browser

Python web frameworks include technologies such as Django, Flask and FastAPI.

// python vs javascript

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.

// execution

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.

Python source code ↓ Compilation ↓ Python bytecode ↓ Python virtual machine ↓ Program executes

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.

// interactive shell

Python can also be used interactively

Python provides an interactive environment where instructions can be entered one at a time.

>>> 2 + 3 5 >>> "hello".upper() 'HELLO'

This makes it convenient for experimentation, calculations and testing small pieces of code.

// readability

Python emphasises readable syntax

Compare the structure of a simple condition:

if balance > 0: print("Positive balance")

Keywords such as if, for, in, def and return make much Python code relatively close to structured written instructions.

// uses

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.

// practical example

One script can connect several technologies

CSV file ↓ Python ↓ Clean data ↓ SQLite database ↓ API request ↓ Create XLSX report ↓ ZIP output files

This ability to connect different formats, systems and services is one reason Python is particularly useful for automation and data-management work.

// mental model

The simplest way to think about Python

Data ↓ Python instructions ↓ Logic + calculations ↓ Files / APIs / databases ↓ Useful result

Python provides a language for describing the operations a computer should perform.

// summary

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.

What Is an .xlsx File?

// spreadsheets

What Is an .xlsx File?

An .xlsx file is a modern spreadsheet file format used by Microsoft Excel and many other spreadsheet programs. It can store worksheets, numbers, text, formulas, tables, charts, formatting and other structured spreadsheet data.

// definition

.xlsx is a spreadsheet file format

An .xlsx file is a spreadsheet workbook stored using Microsoft's Office Open XML spreadsheet format.

It is commonly associated with Microsoft Excel, although other spreadsheet applications can also read and write .xlsx files.

A single workbook can contain multiple worksheets along with formulas, formatting, charts and other spreadsheet information.

// file extension

What does .xlsx mean?

The .xlsx extension identifies an Excel workbook stored using the Office Open XML format.

budget.xlsx customers.xlsx sales-data.xlsx project-tracker.xlsx

The extension tells software what kind of file it is dealing with and which format should be used to interpret the contents.

// workbook

An .xlsx file is a workbook

A workbook can contain one or more worksheets.

sales.xlsx │ ├── January ├── February ├── March └── Summary

Each worksheet contains a grid of rows and columns.

// cells

Spreadsheet data is stored in cells

Each cell is identified by a column and row.

A1 B1 C1 A2 B2 C2

For example:

A B C
Product Quantity Price
Keyboard 2 39.99
Mouse 4 19.50
// cell values

Cells can contain different kinds of information

Text Numbers Dates Times Formulas Booleans Errors
// formulas

.xlsx files can store formulas

A spreadsheet cell does not have to contain only a fixed value.

It can contain a formula:

=A1+B1

or:

=SUM(B2:B20)

The spreadsheet application evaluates the formula and displays the calculated result.

// formula + value

A formula and its displayed result are different things

Suppose a cell contains:

=10+20

The displayed result may be:

30

The workbook can retain the formula rather than simply replacing it with the number 30.

// formatting

.xlsx files can store presentation information

Unlike a simple CSV file, an .xlsx workbook can retain substantial visual formatting.

Fonts Colours Borders Alignment Number Formats Column Widths Row Heights Conditional Formatting
// workbook features

A workbook can contain much more than cells

Worksheets

Multiple spreadsheet pages can exist inside one file.

Charts

Data can be visualised using charts and graphs.

Tables

Structured Excel tables can organise related records.

Formulas

Calculations can reference other cells and sheets.

Validation

Rules can restrict what users are allowed to enter.

Hyperlinks

Cells can contain links to websites and other resources.

// office open xml

An .xlsx file is based on XML

The modern Excel workbook format belongs to the Office Open XML family of file formats.

Internally, workbook information is divided across a collection of structured XML files and related resources.

Workbook ↓ XML documents + relationships + styles + other resources
// zip container

An .xlsx file is also a ZIP package

One of the most interesting facts about .xlsx files is that they are packaged using ZIP compression.

If a copy of an .xlsx file is renamed from:

workbook.xlsx

to:

workbook.zip

ZIP-compatible software can usually open the package and reveal the internal files.

An .xlsx file is not one giant XML document. It is a ZIP package containing multiple XML documents and supporting files organised according to the Office Open XML format.

// internal structure

What is inside an .xlsx file?

A simplified workbook package might contain:

workbook.xlsx │ ├── [Content_Types].xml ├── _rels/ │ ├── docProps/ │ └── xl/ │ ├── workbook.xml ├── styles.xml ├── sharedStrings.xml ├── worksheets/ │ ├── sheet1.xml │ └── sheet2.xml │ └── _rels/

The exact contents depend on which features are used in the workbook.

// worksheet xml

Worksheets are represented using XML

Internally, a worksheet may contain XML structures representing rows and cells.

<row r="1"> <c r="A1"> ... </c> </row>

Spreadsheet software interprets these structures and presents them as the familiar grid seen in Excel.

// shared strings

Text may be stored separately from worksheet cells

Some .xlsx workbooks use a shared strings table.

Instead of repeating the same text many times inside worksheets, cells can reference entries stored in a shared XML structure.

Cell ↓ String reference ↓ sharedStrings.xml ↓ "Freelance Coder"
// styles

Formatting can be stored separately

Workbook styles can be defined in internal style information and referenced by cells.

This avoids having to repeat complete formatting instructions for every individual cell.

// xlsx vs xls

.xlsx replaced the older .xls format

.xls .xlsx
Older Excel format Modern Excel workbook format
Binary file format Office Open XML package
Associated with older Excel versions Introduced with Excel 2007
Legacy format Common modern format
// xlsx vs csv

.xlsx and .csv are very different

CSV XLSX
Plain-text format ZIP-based spreadsheet package
Usually represents one table Can contain multiple worksheets
No native cell formatting Supports extensive formatting
No native charts Can contain charts
Simple data exchange Complete spreadsheet workbook
// important distinction

Saving Excel data as CSV can remove workbook features

Suppose an .xlsx workbook contains:

3 worksheets formulas colours charts cell formatting

Exporting one sheet to CSV normally preserves the tabular values but not the complete workbook structure.

XLSX → full spreadsheet workbook CSV → plain tabular data
// macros

.xlsx files do not normally contain VBA macros

Excel uses a different extension for macro-enabled workbooks:

.xlsm
Extension Workbook type
.xlsx Standard Excel workbook
.xlsm Macro-enabled Excel workbook

This distinction matters. If a workbook depends on VBA macros, saving it as an ordinary .xlsx file is not the appropriate format for retaining those macros.

// programming

.xlsx files can be created by software

Excel itself is not required to generate every .xlsx workbook.

Programming libraries can create, read and modify spreadsheet files automatically.

Python JavaScript PHP Java C# Automation
// python example

Python can create .xlsx files

For example, libraries such as openpyxl can work with Excel workbooks.

from openpyxl import Workbook workbook = Workbook() sheet = workbook.active sheet["A1"] = "Product" sheet["B1"] = "Price" sheet["A2"] = "Keyboard" sheet["B2"] = 39.99 workbook.save("products.xlsx")

Software can therefore generate spreadsheets from databases, APIs and other data sources.

// automation

Spreadsheet generation can be automated

API ↓ Application ↓ Process data ↓ Generate .xlsx ↓ Spreadsheet report

This is useful for reporting, financial data, exports, project tracking and business workflows.

// compatibility

.xlsx files are supported by many applications

Microsoft Excel is the application most strongly associated with .xlsx, but other spreadsheet software can also work with the format.

Microsoft Excel Google Sheets LibreOffice Calc Spreadsheet Libraries

Complex workbook features may not always behave identically when the same file is opened in different spreadsheet applications.

// not plain text

An .xlsx file is not a plain-text file

Although its internal structure contains XML documents, the .xlsx file itself is a compressed package.

Opening it directly in a basic text editor will therefore not display the workbook in the same clean way as opening a CSV, TXT or XML file.

TXT → plain text CSV → plain text XML → plain text XLSX → compressed package containing XML and other resources
// uses

What are .xlsx files used for?

Budgets Accounts Data Analysis Reports Project Tracking Invoices Customer Lists Dashboards Financial Models Data Exports
// mental model

The simplest way to think about .xlsx

.xlsx file ↓ ZIP package ↓ XML + relationships + resources ↓ Workbook ↓ Worksheets ↓ Rows + columns + cells ↓ Values + formulas + formatting
// summary

More than just a table.

An .xlsx file is a modern spreadsheet workbook format based on Office Open XML. It can contain multiple worksheets, values, formulas, formatting, charts and other spreadsheet features. Internally, the workbook is stored as a ZIP package containing XML documents and related resources.

What Is SQLite?

// databases

What Is SQLite?

SQLite is a lightweight relational database system that stores an entire database in a file. Unlike many database systems, it does not require a separate database server running in the background.

// definition

SQLite is an embedded relational database

SQLite is a relational database management system designed to be embedded directly inside applications.

A complete SQLite database is commonly stored in a single file on disk.

Applications interact with that file using SQL commands such as SELECT, INSERT, UPDATE and DELETE.

// simple idea

A database can be just one file

A SQLite database might look like this:

customers.db

Inside that file could be several tables:

customers orders products payments

The application can open the database file and query those tables directly.

// serverless

SQLite does not need a separate database server

Systems such as MySQL and PostgreSQL normally run as separate database server processes.

Applications connect to those servers over a local connection or network connection.

SQLite works differently.

Application ↓ SQLite library ↓ database.db

The application accesses the database through the SQLite library rather than contacting a separate database server.

// sql

SQLite uses SQL

SQL stands for Structured Query Language.

SQL is used to create, read, update and delete data stored in relational databases.

SELECT * FROM customers;

This query asks SQLite to return all rows from the customers table.

// tables

SQLite stores data in tables

A customer table might contain:

id name email
1 Alice alice@example.com
2 Ben ben@example.com
3 Carla carla@example.com

Each row represents a record, while each column represents a particular type of information.

// create table

Tables can be created with SQL

CREATE TABLE customers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT );

This creates a table containing three columns:

id name email
// insert

Data can be inserted

INSERT INTO customers ( name, email ) VALUES ( 'Alice', 'alice@example.com' );

This adds a new row to the customers table.

// select

Data can be retrieved

SELECT name, email FROM customers;

A condition can also be added:

SELECT * FROM customers WHERE id = 1;

This retrieves the customer whose ID is 1.

// update

Existing data can be changed

UPDATE customers SET email = 'alice.new@example.com' WHERE id = 1;

This changes the email address associated with the selected row.

// delete

Rows can be deleted

DELETE FROM customers WHERE id = 1;

The matching row is removed from the table.

// crud

These operations are often called CRUD

Create

Add new records to the database.

Read

Retrieve existing information.

Update

Change existing records.

Delete

Remove records from the database.

// relational

SQLite is a relational database

Relational databases can connect information stored across different tables.

For example:

customers id | name 1 | Alice orders id | customer_id | total 1001 | 1 | 49.99 1002 | 1 | 18.50

The customer_id value connects the orders to Alice's customer record.

// joins

SQL can combine related tables

SELECT customers.name, orders.total FROM customers JOIN orders ON customers.id = orders.customer_id;

The database can use the relationship between the tables to combine the relevant information.

// files

SQLite databases can use different file extensions

You may encounter files such as:

data.db database.sqlite app.sqlite3 customers.db

The extension does not fundamentally determine whether the file is a SQLite database. It is mainly a naming convention.

// storage classes

SQLite can store several kinds of values

Storage class Purpose
NULL No value
INTEGER Whole numbers
REAL Floating-point numbers
TEXT Text strings
BLOB Binary data
// embedded

SQLite is often embedded inside applications

Software can include SQLite as part of the application itself.

The user may never even realise that a SQLite database is being used.

Desktop Apps Mobile Apps Browsers Local Tools Development Testing
// portable

SQLite databases are highly portable

Because a database can be stored in a single file, it can be straightforward to copy, back up or move.

project/ │ ├── app.py ├── database.db └── settings.json

The database can sit directly alongside the application files.

// sqlite vs csv

SQLite is very different from CSV

CSV SQLite
Plain-text file Database file
Usually one table Can contain many tables
No SQL engine Supports SQL queries
Limited relationships Relational structure
Simple data exchange Application data storage
// sqlite vs mysql

SQLite and MySQL use different architectures

SQLite MySQL
Embedded database Database server
Database commonly stored in one file Server manages database storage
No separate server required Requires database server software
Excellent for local and embedded use Common for networked applications
// sqlite vs server database

SQLite is not designed for every database workload

SQLite is extremely useful when simplicity and local storage are important.

A dedicated database server such as PostgreSQL or MySQL may be more appropriate when an application requires many simultaneous writers, centralised access, extensive server administration or large multi-user workloads.

SQLite is not simply a smaller MySQL. Its architecture is deliberately different. It is designed to provide a database engine directly inside an application.

// transactions

SQLite supports transactions

A transaction allows several database operations to be treated as one logical unit.

BEGIN; UPDATE accounts SET balance = balance - 50 WHERE id = 1; UPDATE accounts SET balance = balance + 50 WHERE id = 2; COMMIT;

Transactions help protect data from being left in an incomplete state if an operation fails.

// reliability

SQLite supports ACID transactions

Atomicity

A transaction is completed as a unit or rolled back.

Consistency

Database rules can help preserve valid states.

Isolation

Transactions are managed to avoid unsafe interference.

Durability

Committed changes are designed to survive failures.

// indexes

Indexes can improve query performance

CREATE INDEX idx_customer_email ON customers(email);

An index can allow the database to find certain values more efficiently instead of examining every row.

// programming

Many programming languages can use SQLite

Python PHP JavaScript C C++ Java C# Swift
// example with python

SQLite can be used from application code

For example, Python includes support for SQLite:

import sqlite3 connection = sqlite3.connect("customers.db") cursor = connection.cursor() cursor.execute( "SELECT * FROM customers" ) rows = cursor.fetchall() connection.close()

The program opens the database file, executes a query and retrieves the results.

// uses

What is SQLite used for?

Mobile Apps Desktop Software Local Data Application Settings Prototypes Testing Small Websites Data Analysis Embedded Systems Offline Applications
// advantages

Why is SQLite useful?

Simple

No separate database server needs to be configured.

Portable

An entire database can commonly be stored in one file.

Lightweight

The database engine can be embedded directly inside an application.

Powerful

It still provides SQL, transactions, indexes, relationships and many database features.

// important distinction

A SQLite database is more than an ordinary data file

A CSV file stores rows of text.

A JSON file stores structured text.

A SQLite file contains a database managed by an actual database engine.

CSV → data file JSON → structured data file SQLite → database stored in a file

That distinction is important.

// summary

A database inside one file.

SQLite is an embedded relational database system that provides SQL, tables, relationships, transactions and indexes without requiring a separate database server. Its simplicity and portability make it useful for mobile apps, desktop software, local tools, prototypes and many other applications.

What Is an IP Address?

// networking What Is an IP Address? An IP address is a numerical address used t...