Guide for JavaScript developers
Python for JavaScript Developers: Learn Python Using What You Already Know
Already know JavaScript? Discover how familiar programming concepts translate into Python, what works differently, and the fastest path to getting productive.
JavaScript vs Python, side by side
Each pair below does the same job. Start with the code you know, then see how Python expresses it.
Variables: let, const and undefined
let count = 0;
const limit = 10;
let missing; // undefinedcount = 0
LIMIT = 10 # constant by convention only
missing = NonePython has no let or const: assignment creates the name, and an uppercase name is only a convention. There is no undefined: reading an unassigned name raises NameError, a missing key raises KeyError, and None is an explicit empty value.
Objects vs dictionaries
const user = { name: "Ada", age: 36 };
user.email = "ada@example.com";
delete user.age;
console.log("name" in user);user = {"name": "Ada", "age": 36}
user["email"] = "ada@example.com"
del user["age"]
print("name" in user)Dictionaries use [] with string keys, never dot access, and user.get("age") returns None instead of raising KeyError. A dictionary holds data only: for data with behavior, define a class.
map/filter vs comprehensions
const doubled = nums
.filter(n => n > 0)
.map(n => n * 2);doubled = [n * 2 for n in nums if n > 0]
square = lambda n: n * nA comprehension replaces most filter and map chains. Python also has lambda, but it is limited to a single expression, so use def for anything longer; there is no arrow-function syntax. Python's built-in versions return lazy iterators, not lists.
async/await
async function loadAll(urls) {
return Promise.all(urls.map(fetchText));
}import asyncio
async def load_all(urls):
return await asyncio.gather(*(fetch_text(url) for url in urls))async and await look alike, but a Python coroutine does not start until it is awaited or scheduled, while a JavaScript Promise starts running immediately. Python gives you no running event loop by default: start one with asyncio.run(...).
What JavaScript developers need to unlearn
A few habits carry over badly. These shifts matter most.
Indentation is the syntax
Blocks start with a colon and are defined by indentation instead of braces, and semicolons are not used. Use four spaces and stay consistent.
Truthiness and types differ
Empty lists, dictionaries and strings are falsy in Python, unlike an empty array in JavaScript, and
Nonereplaces bothnullandundefined. Compare withis None, not==.Comprehensions replace map and filter
A comprehension such as
[n * 2 for n in nums if n > 0]does the job offilterfollowed bymapin one readable line.Lean on built-in collections
Lists, dictionaries, sets and tuples cover what you use arrays, objects,
MapandSetfor. Useinto test membership andlen(items)instead of.length.Write Python, not JavaScript in Python
Skip callbacks where a loop or comprehension reads better. Use
snake_caseinstead ofcamelCase, andand,or,notinstead of&&,||,!.
Your JavaScript-to-Python learning roadmap
Translate familiar concepts
Map familiar syntax and concepts to Python.
Learn Python's differences
Collections, functions, idiomatic style.
Practice with real code
Solve small problems, not just read.
Build confidence
Harder, more realistic challenges.
Hintor's Python for Developers track is designed for developers switching languages, with hands-on practice built into the lessons. Explore the Python for Developers track
Mini challenge
Given a list of integers, write Python code that creates a new list containing the squares of only the even numbers.
- Input
- [1, 2, 3, 4, 5, 6]
- Expected output
- [4, 16, 36]
Hint: a list comprehension can include an if filter, and n % 2 == 0 tests whether n is even.
numbers = [1, 2, 3, 4, 5, 6]
even_squares = [n * n for n in numbers if n % 2 == 0]
print(even_squares) # [4, 16, 36]The comprehension reads left to right: compute n * n for each n in numbers, keeping only the even ones. A regular for loop with append works too; the comprehension is the idiomatic shortcut.
Ready to Turn Your JavaScript Knowledge into Python Skills?
You already know how to program. Now learn to think in Python with guided lessons and hands-on practice.
Start Learning Python on Hintor