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

JavaScript
let count = 0;
const limit = 10;
let missing;            // undefined
Python
count = 0
LIMIT = 10              # constant by convention only
missing = None

Python 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

JavaScript
const user = { name: "Ada", age: 36 };
user.email = "ada@example.com";
delete user.age;
console.log("name" in user);
Python
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

JavaScript
const doubled = nums
  .filter(n => n > 0)
  .map(n => n * 2);
Python
doubled = [n * 2 for n in nums if n > 0]

square = lambda n: n * n

A 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

JavaScript
async function loadAll(urls) {
  return Promise.all(urls.map(fetchText));
}
Python
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 None replaces both null and undefined. Compare with is None, not ==.

  • Comprehensions replace map and filter

    A comprehension such as [n * 2 for n in nums if n > 0] does the job of filter followed by map in one readable line.

  • Lean on built-in collections

    Lists, dictionaries, sets and tuples cover what you use arrays, objects, Map and Set for. Use in to test membership and len(items) instead of .length.

  • Write Python, not JavaScript in Python

    Skip callbacks where a loop or comprehension reads better. Use snake_case instead of camelCase, and and, or, not instead of &&, ||, !.

Your JavaScript-to-Python learning roadmap

  1. Translate familiar concepts

    Map familiar syntax and concepts to Python.

  2. Learn Python's differences

    Collections, functions, idiomatic style.

  3. Practice with real code

    Solve small problems, not just read.

  4. 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.

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
Python for JavaScript Developers | Learn Python Faster – Hintor