Skip to lesson
Python for JS Developers

Syntax BridgeLesson 1 of 4

Variables & Types

4 min

Coming from JS, the first thing you will notice is that Python does not need keywords to declare variables. No let, no const, no var. You write the name and assign a value. That is it.

But here is what catches most JS developers off guard: Python is strongly typed. In JS, "5" + 5 gives you "55" because JS silently converts the number. Python refuses and raises a TypeError, making you handle the conversion yourself. This strictness feels annoying at first, but it prevents a whole category of bugs you have probably spent hours debugging in JS. Python is still dynamically typed, though: a variable can hold a string now and a number later. Strong typing means no silent conversions, not fixed types.

Another quick shift: Python uses snake_case for variables and functions, PascalCase for classes, and UPPER_CASE for constants. So firstName becomes first_name, and isActive becomes is_active. Your editor will remind you, but your muscle memory will fight back for about a week.

Naming rules you need to know right now: variable names can contain letters, numbers, and underscores, but cannot start with a number. 2ndPlace is illegal. Names starting with an underscore have special meaning: _name signals 'this is internal, do not touch' (a convention, not enforced). __name triggers name mangling inside classes (Python renames it to make accidental access from outside harder). And names with double underscores on both sides, like __init__ and __str__ ("dunder" names), are reserved for Python's own special methods and attributes. Never invent your own dunder names.

Python 3.12 has 35 reserved keywords you cannot use as names: False, None, True, and, as, assert, async, await, break, class, continue, def, del, elif, else, except, finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass, raise, return, try, while, with, yield. There are also a few soft keywords (match, case, type, and _) that are only special in specific positions, so they still work as ordinary names. Finally, avoid shadowing built-in function names like list, dict, str, int, type, print, len, input, or id. Writing list = [1, 2, 3] silently breaks the list() built-in in that scope.

Quick reference

JavaScriptPythonNote
let / const / varjust assignNo declaration keyword needed
true / falseTrue / FalseCapital first letter!
null / undefinedNoneOne value, not two
typeof xtype(x)A function; use isinstance() for checks
"5" + 5 = "55"TypeError!No implicit coercion
camelCasesnake_caseConvention (PEP 8), not enforced

Side by side

JavaScript
// JavaScript
let name = "Alice";
const age = 28;
var isActive = true;

// Type coercion (JS magic)
console.log("5" + 5);  // "55"
console.log("5" - 2);  // 3
Python
# Python
name = "Alice"
age = 28
is_active = True  # True/False, not true/false

# No type coercion
# "5" + 5  -> TypeError!
print("5" + str(5))   # "55" - explicit conversion
print(int("5") - 2)   # 3

name = 42             # dynamic: a name can be rebound to any type

Exercise

Real Python, running in your browser

Convert this JavaScript to Python:

JavaScript to convert
// JavaScript
const firstName = "John";
let score = 95;
const passed = true;
console.log(firstName + " scored " + score);
Expected output
John scored 95

Ctrl + Enter runCtrl + Shift + Enter checkTab indentEsc then Tab to leave the editorCtrl + / comment