Menu
CoddyTech
Course

Python for Lua Developers

Move from Lua tables and metatables to Python collections and classes. Compare truthiness, indexing, multiple returns, closures, exceptions, and module loading, then build a connected order processor.

Lua and Python side by side

The same program in Lua and in Python, from the lessons of this course.

  1. Printing and Text

    Lua print separates arguments with tabs; Python print uses spaces by default. Python strings may use either quote style, but represent Unicode text rather than Lua byte strings. Use # for Python comments instead of Lua --. Concatenate Python strings with +…

    Lua
    1-- Readable status2print("Status:", "ready")3print("Don't stop")
    Python
    1# A comment for readers2print("Status:", "ready")3print("Don't stop")
  2. nil Versus None

    Python uses the singleton None to represent absence and tests it with is None. Lua uses nil, which also removes a table key when assigned as its value. Python dictionaries can store None as an actual value without removing a key. Missing Python dictionary…

    Lua
    1local seats = nil2print(seats == nil)3local values = {seat = 2}4values.seat = nil5print(values.seat == nil)
    Python
    1seats = None2print(seats is None)3available = False4print(available)
  3. Sequence Tables to Lists

    Lua sequence conventions usually start at one. Python lists start at zero and negative indexes count from the end. Use append to add an item; it mutates the list and returns None. Python lists cannot contain absent slots: None is a real element and counts…

    Lua
    1local items = {4, 8}2table.insert(items, 12)3print(items[#items])4print(items[1])
    Python
    1items = [4, 8]2items.append(12)3print(items[-1])4print(items[:2])
  4. Numeric for to range

    Lua numeric for loops include the end value when the step reaches it. Python range excludes its stop value. Python for iterates values directly; there is no need for Lua ipairs when the index is unused. Iterating a list binds each element object to the loop…

    Lua
    1for _, value in ipairs({2, 4}) do print(value) end2for i = 0, 3 do print(i) end
    Python
    1for value in [2, 4]:2    print(value)3for i in range(3):4    print(i)
  5. Returns and Shared Parameters

    Python defines functions with def, parentheses, a colon, and an indented body. Like Lua, it needs an explicit return to send a useful result to a caller. A Python function that falls through returns None; Lua falls through with no results, often adjusted to…

    Lua
    1local function twice(value)2    return value * 23end4print(twice(4))
    Python
    1def twice(value):2    return value * 23print(twice(4))
  6. Input and Exact Text

    Lua io.read commonly returns nil at end of input. Python input returns a string without its final newline and raises EOFError when input is exhausted. strip removes outer whitespace and split without arguments splits on whitespace runs. Python f-strings embed…

    Lua
    1local label = ("  Green tea  "):match("^%s*(.-)%s*$")2local cents = 3053print(string.format("%s: %d.%02d", label, math.floor(cents / 100), cents % 100))
    Python
    1label = "  Green tea  ".strip()2cents = 3053print(f"{label}: {cents // 100}.{cents % 100:02d}")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Apply Your Lua Experience

2 lessons

More courses for Lua developers

Learn Python from another language

Frequently asked questions

Who is Python for Lua Developers for?

For people who already write Lua and want to learn Python. Each lesson starts from Lua you know and shows how Python does the same thing, so you skip the beginner basics.

Do I need to know Python already?

No. The course starts with your first Python program. You need Lua basics: variables, conditions, loops, functions and collections.

How many lessons does Python for Lua Developers have?

Python for Lua Developers contains 48 interactive lessons you can complete at your own pace.

What does Python for Lua Developers cover?

The course is organized into chapters covering: From Lua to Python, Values and Decisions, Tables to Typed Collections, Iteration and Transformations, and more.

Is Python for Lua Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Python for Lua Developers for free

Get started