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.
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 +…
Lua1-- Readable status2print("Status:", "ready")3print("Don't stop")Python1# A comment for readers2print("Status:", "ready")3print("Don't stop")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…
Lua1local seats = nil2print(seats == nil)3local values = {seat = 2}4values.seat = nil5print(values.seat == nil)Python1seats = None2print(seats is None)3available = False4print(available)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…
Lua1local items = {4, 8}2table.insert(items, 12)3print(items[#items])4print(items[1])Python1items = [4, 8]2items.append(12)3print(items[-1])4print(items[:2])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…
Lua1for _, value in ipairs({2, 4}) do print(value) end2for i = 0, 3 do print(i) endPython1for value in [2, 4]:2 print(value)3for i in range(3):4 print(i)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…
Lua1local function twice(value)2 return value * 23end4print(twice(4))Python1def twice(value):2 return value * 23print(twice(4))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…
Lua1local label = (" Green tea "):match("^%s*(.-)%s*$")2local cents = 3053print(string.format("%s: %d.%02d", label, math.floor(cents / 100), cents % 100))Python1label = " Green tea ".strip()2cents = 3053print(f"{label}: {cents // 100}.{cents % 100:02d}")
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFrom Lua to Python
6 lessonsValues and Decisions
5 lessonsTables to Typed Collections
5 lessonsIteration and Transformations
5 lessonsFunctions and Closures
5 lessonsErrors and Modules
5 lessonsClasses Beyond Metatables
6 lessonsComposition and Dispatch
5 lessonsProject: Order Processing
4 lessonsApply Your Lua Experience
2 lessonsFrequently 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.