Lesson 32 of 55
9 mins readPython Quoting Expressions & Interpolation ($)
In Plain English
Quoting prevents immediate evaluation and creates an expression. Use :(1 + 2) for one-liners, quote ... end for multi-line blocks, and $ to inject values into expressions.
Deep Dive: How It Works
Quoting Syntax: :(x + y) builds an Expr without evaluating x or y yet.
quote ... end Blocks: Construct multi-line expression trees with line number metadata.
Expression Interpolation ($): Inside quoted expressions, $var evaluates var and splices its value directly into the AST.
Core Rules to Remember

:( ... ) Quoting: Treat code as a literal expression object.

$ Splice Operator: Inject computed values or sub-expressions directly into quoted AST trees.
Live Interactive Example
Hit Run Code to see it liveQuoting and Expression Splicing
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output Console
Click "Run Code" to view the rendered output.
How it works: $multiplier inserted the literal 5 into the AST node.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Interpolate Symbol into Quoted Expr
Set `val = 100`.
Create `expr = :( a + $val )`.
Print `"Built expression: $expr"`.
1
2
3
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.