Lesson 20 of 55
8 mins readPython Quote Words (qw//) & List Assignments
In Plain English
The `qw(...)` (quote words) operator creates a list of whitespace-separated strings without quotes or commas. Perl also supports parallel list assignments for variable swapping.
Deep Dive: How It Works
qw Operator: `qw(red green blue)` is identical to `("red", "green", "blue")`.
Custom Delimiters: Use `qw//`, `qw{}`, `qw[]`, or `qw!!` interchangeably.
Parallel Assignment: `($a, $b) = ($b, $a)` swaps variables without a temporary variable.
Core Rules to Remember

qw// Shortcut: Saves typing quotes and commas when creating lists of words.

List Swapping: Swaps values in a single atomic assignment.
Live Interactive Example
Hit Run Code to see it liveqw Words and List Swapping
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: qw split words by space, and list assignment swapped $alpha and $beta.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Swap Two Coordinates
Initialize `my ($x, $y) = (10, 20);`
Swap them using `($x, $y) = ($y, $x);`
Print `"Swapped: x=$x, y=$y\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.