Python Reference -- PAGE UNDER CONSTRUCTION --
Python & Programming Concepts
Created by Guido van Rossum (Netherlands, 1991), Python's syntax mirrors the English language, letting developers accomplish more with fewer lines of code. It runs cross-platform on Windows, Mac, and Linux.
Python is an interpreted (scripting) language — the interpreter executes code line-by-line at run-time, unlike compiled languages that translate the entire program before execution.
Variables
Named containers for storing and referencing data values in a program.
In Python, a variable is created at the moment you first assign a value — no explicit declaration needed. Variables are dynamically typed and can change type after being set.
- Created on first assignment — no declaration command
- Dynamically typed; type can change at any time
- Cannot begin with a number — only letters or underscore
- Case-sensitive:
age,Age, andAGEare three distinct variables - Alphanumeric + underscore only; no hyphens or spaces
- String and int cannot be concatenated directly with
+ - Use
globalkeyword to modify global variable inside a function
Use var, let, or const. Values in quotes. End statements with semicolon.
Prefer const/let over var in modern JS.
All variables must begin with $. Semicolons required. No type declaration needed.
Input and Output
Reading data from the user and displaying results — a program's primary communication channel.
| JavaScript | PHP |
|---|---|
name = prompt("Your name?") |
Use $_POST or $_GET superglobals for form input |
alert("Hello, " + name)console.log(name) |
echo "Hello " . $name;print("Hello"); |
Strings
Ordered sequences of characters enclosed in quotes. The most common data type in web programming.
In Python, strings are arrays of characters — you can index and slice them.
An escape character is a backslash \ followed by the intended character.
- Strings are arrays — access via index:
a[0] - Slicing:
a[start:end]— end index is exclusive - Escape with backslash:
\"\'\n\t
| JavaScript | PHP |
|---|---|
document.write("Hi " + aName); |
$s = "this is a string"; |
Template literals: `Hello ${name}` |
Concatenate with . (dot): "Hi " . $name |
"text".length |
strlen($s) |
Arrays & Collections
Python provides four built-in collection types — each suited to different data-storage needs.
list_name = [item1, item2, ...]
— e.g. cars = ["Saab", "Volvo", "BMW"]
PHP's powerful associative arrays work like Python dictionaries, with many built-in functions.
List
General-purpose ordered collection. The Python equivalent of an array.
Use square brackets [ ]
Tuples
Immutable ordered collection. Faster iteration than lists; can be used as dictionary keys.
Use round brackets ( )
Sets
Unordered, unindexed. Ideal for membership testing and removing duplicates.
Use curly brackets { }
Dictionaries
Key-value store. Keys must be unique and immutable; values are freely changeable.
Syntax: {key: value, ...}
Conditional Statements — if | else
Control structures alter the flow of execution. Flavours: if, if|else, if|elif|else.
if (expr) { ... } else if (expr) { ... } else { ... }
Loops & Iterations
while — indefinite, runs until condition is false. for — definite, iterates a sequence.
Supports for, while, do...while, for...of (arrays), and for...in (object keys).
Loop syntax mirrors JavaScript: for ($i=0; $i<5; $i++) and
foreach ($arr as $key => $val) for arrays.
Functions
Reusable named blocks of code. Define once, call anywhere. Reduces duplication.
Operators
Symbols that perform operations on variables and values.
Environment Setup & IDEs
Tools and resources to get your Python development environment running.
An IDE (Integrated Development Environment) combines a code editor, debugger, and build tools in one application.
- PyCharm — Full-featured Python IDE (JetBrains)
- VS Code — Lightweight, highly extensible, most popular
- Atom — Open-source hackable editor (GitHub)
- Eclipse — Java-based, multi-language with PyDev plugin
- Repl.it — Free web-based IDE — no installation needed
Visualise algorithms and pseudocode before writing a single line of code.