I'll guide you through Python fundamentals by comparing concepts with JavaScript. Let's start!
1. Hello World & Basic Syntax
JavaScript
console.log("Hello World");
let x = 5;
Python
print("Hello World")
x = 5 # No semicolon, no let/const
Key Differences:
- No semicolons in Python
- Indentation matters (replaces curly braces)
- Comments use
#instead of//
2. Variables & Data Types
JavaScript
let name = "Alice"; // string
let age = 30; // number
let isStudent = true; // boolean
let scores = [95, 87, 91]; // array
let person = { // object
name: "Bob",
age: 25
};
let nothing = null;
let notDefined = undefined;
Python
name = "Alice" # str
age = 30 # int (or float for decimals)
is_student = True # bool (capital T/F)
scores = [95, 87, 91] # list (mutable)
person = { # dict (dictionary)
"name": "Bob",
"age": 25
}
nothing = None # Python's null/undefined
Key Differences:
- Python uses snake_case (not camelCase)
-
True/Falsecapitalized -
Noneinstead ofnull/undefined - Lists ≈ Arrays, Dicts ≈ Objects
3. Control Flow
JavaScript
// If-else
if (age >= 18) {
console.log("Adult");
} else if (age >= 13) {
console.log("Teen");
} else {
console.log("Child");
}
// For loop
for (let i = 0; i < 5; i++) {
console.log(i);
}
// While loop
let count = 0;
while (count < 5) {
console.log(count);
count++;
}