Lesson 27 of 55
8 mins readPython Tables as Dictionaries (Key-Value Maps)
In Plain English
When indexing tables with string keys, `t.field` is direct syntactic sugar for `t["field"]`. Any non-nil value can serve as a key in a table.
Deep Dive: How It Works
Dot Syntax: `user.name` is identical to `user["name"]`.
Bracket Syntax: `t[expr]` evaluates `expr` (required when keys contain spaces or special characters).
Deleting Keys: Assigning `t[key] = nil` permanently removes the key from the table.
Core Rules to Remember

Dot vs Bracket Syntax: `t.key` for valid identifiers; `t["key"]` for dynamic or arbitrary keys.

Key Deletion with nil: Setting a field to `nil` removes it completely from memory.
Live Interactive Example
Hit Run Code to see it liveDictionary Fields and Deletion
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
Output Console
Click "Run Code" to view the rendered output.
How it works: Dot and bracket syntax fetched values, and setting level to nil removed it.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Configure Service Map
Declare `local service = { host = "api.zencompiler.com", port = 8080 }`.
Print `"Endpoint: " .. service.host .. ":" .. service.port`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.