Lesson 25 of 55
9 mins readPython Hash Fundamentals: Sigil (%) & Fat Comma (=>)
In Plain English
Perl hashes are unordered collections of unique key-value pairs denoted by the `%` sigil. The "fat comma" (`=>`) quotes its left operand as a string key.
Deep Dive: How It Works
Sigil Transition: Whole hash is `%config`, but accessing a single key uses curly braces and dollar sign `$config{"port"}`.
Fat Comma (=>): Synonym for comma that auto-quotes the left identifier (e.g. `host => "localhost"`).
Unordered: Hash keys are stored in a hash table and do not preserve insertion order.
Core Rules to Remember

% for Hash, $ for Value Lookup: Use `%hash` for the whole hash and `$hash{key}` with curly braces for lookups.

Fat Comma (=>): Clean syntax pairing keys with values.
Live Interactive Example
Hit Run Code to see it liveCreating and Accessing Hashes
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Output Console
Click "Run Code" to view the rendered output.
How it works: $user{name} fetched the value associated with the "name" key.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Define Server Config Hash
Declare `%server = ( host => "zencompiler.com", port => 443 );`
Print `"Connect to $server{host}:$server{port}\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.