Lesson 12 of 55
15 mins readPython Index Signatures and Record
In Plain English
When you do not know all property keys ahead of time, index signatures and Record<K, V> allow you to type dictionary lookups and dynamic key-value structures safely.
Core Rules to Remember

Index Signatures: Syntax [key: string]: Value allows arbitrary string or number property keys.

Record<K, V>: Built-in utility type providing clean map typing over known key unions.
Live Interactive Example
Hit Run Code to see it liveIndex Signatures and Record Types
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Output Console
Click "Run Code" to view the rendered output.
How it works: HeaderMap accepts any arbitrary string keys, while statusMessages enforces exact completeness across StatusCode.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Create an Environment Variable Registry
Use Record to define type EnvVars as a map from "PORT" | "HOST" | "NODE_ENV" to string.
Create an env object of type EnvVars with PORT "3000", HOST "localhost", and NODE_ENV "development".
Print HOST and PORT.
1
2
3
4
5
6
7
8
9
10
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.