Python Punctuation Cheat Sheet
Python Punctuation Guide
Page 1 of 2
Syntax symbols, brackets, and code structure reference for beginners
Python 3 Reference Desk Reference Card
Key Rule: Python uses indentation instead of curly braces to group code, but it is extremely strict about punctuation!
Syntax Matters
The 3 Essential Brackets (Never Mix These Up!) Must Always Pair Up
( ) Parentheses
Calls functions, passes arguments, groups math operations, and makes tuples.
print("Score:", s)
total = (3 + 5) * 2
[ ] Square Brackets
Creates Lists and accesses items by index number (starts at 0).
items = ["a", "b"]
first = items[0]
{ } Curly Braces
Builds Dictionaries (key-value) and holds variables inside f-strings.
user = {"hp": 100}
f"HP: {user['hp']}"
Code Structure & Flow
<table class="w-full text-xs border-collapse flex-1"><tbody class="divide-y divide-slate-100"><tr><td class="p-2 font-mono font-black text-rose-600 text-base w-10 text-center bg-rose-50/50 align-top">:</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Colon (Header Terminator)</div><div class="text-[10px] text-slate-600 leading-tight">Signals that an <em>indented block</em> begins on the next line! Required after <code class="font-mono text-slate-800">if</code>, <code class="font-mono text-slate-800">elif</code>, <code class="font-mono text-slate-800">else</code>, <code class="font-mono text-slate-800">for</code>, <code class="font-mono text-slate-800">while</code>, and <code class="font-mono text-slate-800">def</code>.</div><div class="font-mono text-[10px] text-purple-700 mt-1 bg-slate-50 p-1 rounded border border-slate-200"><span class="text-blue-600 font-bold">if</span> score >= 90<span class="text-rose-600 font-black">:</span><br> print(<span class="text-amber-600">"A!"</span>)</div></td></tr><tr><td class="p-2 font-mono font-black text-emerald-600 text-base w-10 text-center bg-emerald-50/50 align-top">#</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Hash / Octothorpe (Single-Line Comment)</div><div class="text-[10px] text-slate-600 leading-tight">Python ignores anything following <code class="font-mono">#</code> on that line. Perfect for student notes, instructions, and testing.</div><div class="font-mono text-[10px] text-emerald-700 mt-1 bg-slate-50 p-1 rounded border border-slate-200"># Remember to validate input</div></td></tr><tr><td class="p-2 font-mono font-black text-slate-500 text-base w-10 text-center bg-slate-100 align-top">;</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Semicolon (Not Needed in Python!)</div><div class="text-[10px] text-slate-600 leading-tight">Unlike Java/C++, Python uses newlines instead of semicolons. You almost never write semicolons in Python!</div></td></tr></tbody></table>
Quotes & String Syntax
<table class="w-full text-xs border-collapse flex-1"><tbody class="divide-y divide-slate-100"><tr><td class="p-2 font-mono font-bold text-amber-600 text-sm w-12 text-center bg-amber-50/40 align-top">' ' • " "</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Single vs Double Quotes</div><div class="text-[10px] text-slate-600 leading-tight">Both create text strings. Python treats them identically! Choose one, but the start and end quote must match.</div><div class="font-mono text-[10px] text-slate-800 mt-1 bg-slate-50 p-1 rounded border border-slate-200"><span class="text-amber-700">"hello"</span> == <span class="text-amber-700">'hello'</span></div></td></tr><tr><td class="p-2 font-mono font-bold text-amber-700 text-xs w-12 text-center bg-amber-50/70 align-top">""" """</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Triple Quotes (Multi-Line Text)</div><div class="text-[10px] text-slate-600 leading-tight">Allows strings across multiple lines without syntax errors. Often used for function docstrings.</div><div class="font-mono text-[10px] text-slate-800 mt-1 bg-slate-50 p-1 rounded border border-slate-200">msg = <span class="text-amber-800">"""Line 1<br>Line 2"""</span></div></td></tr><tr><td class="p-2 font-mono font-bold text-purple-700 text-sm w-12 text-center bg-purple-50/50 align-top">\</td><td class="p-2 align-top"><div class="font-bold text-slate-900 text-[11px]">Backslash (Escape Character)</div><div class="text-[10px] text-slate-600 leading-tight">Creates special characters: <code class="font-mono text-purple-700 font-bold">\n</code> (newline), <code class="font-mono text-purple-700 font-bold">\t</code> (tab), <code class="font-mono text-purple-700 font-bold">\'</code> (quote inside quote).</div><div class="font-mono text-[10px] text-slate-800 mt-1 bg-slate-50 p-1 rounded border border-slate-200">print(<span class="text-amber-700">"Item 1\nItem 2"</span>)</div></td></tr></tbody></table>
Crucial Concept The Equals Sign Showdown: = vs ==
= Single Equals = Assignment
Takes the value on the right and stores it into the variable on the left.
player_health = 100
== Double Equals = Comparison
Asks a yes/no question: "Are these two sides equal?" Returns True or False.
if player_health == 0:
Rule: If you open a ( [ { ' " you MUST close it!
Turn page for Operators & Error Decoder →
Python Punctuation Guide
Page 2 of 2
Operators, navigation symbols, slicing syntax, and error debugging
Operators & Errors Desk Reference Card
Math & Arithmetic Symbols
<table class="w-full text-xs border-collapse"><tbody class="divide-y divide-slate-100 text-[11px]"><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-slate-900 w-12 text-center bg-slate-50">+ - *</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Add, Subtract, Multiply</span><br><code class="font-mono text-[10px] text-slate-600">5 * 4 = 20</code> (asterisk is multiply)</td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-blue-700 w-12 text-center bg-blue-50/50">/</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Standard Division (Float)</span><br><code class="font-mono text-[10px] text-blue-700 font-bold">7 / 2 → 3.5</code> (always returns float)</td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-indigo-700 w-12 text-center bg-indigo-50/50">//</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Floor Division (Integer)</span><br><code class="font-mono text-[10px] text-indigo-700 font-bold">7 // 2 → 3</code> (chops decimal, rounds down)</td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-amber-700 w-12 text-center bg-amber-50/50">%</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Modulo (Remainder)</span><br><code class="font-mono text-[10px] text-amber-700 font-bold">7 % 2 → 1</code> (<code class="font-mono text-[10px]">n % 2 == 0</code> tests even!)</td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-purple-700 w-12 text-center bg-purple-50/50">**</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Exponent / Power</span><br><code class="font-mono text-[10px] text-purple-700 font-bold">2 ** 3 → 8</code> (not <code class="font-mono">^</code>, which is XOR!)</td></tr></tbody></table>
Comparisons & Shortcuts
<table class="w-full text-xs border-collapse"><tbody class="divide-y divide-slate-100 text-[11px]"><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-rose-700 w-12 text-center bg-rose-50/50">!=</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Not Equal To:</span> <code class="font-mono text-[10px]">x != y</code><br><span class="text-[10px] text-slate-500">Exclamation mark means "NOT".</span></td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-slate-800 w-12 text-center bg-slate-50">> • <</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Strictly Greater / Less than:</span><br><code class="font-mono text-[10px]">score > 50</code> or <code class="font-mono text-[10px]">temp < 32</code></td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-slate-800 w-12 text-center bg-slate-50">>= • <=</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Greater/Less or Equal To:</span><br><span class="text-[10px] text-slate-500">Always write the <code class="font-mono">></code> or <code class="font-mono"><</code> before the <code class="font-mono">=</code>!</span></td></tr><tr class="hover:bg-slate-50"><td class="p-1.5 font-mono font-bold text-cyan-700 w-12 text-center bg-cyan-50/50">+= • -=</td><td class="p-1.5 text-slate-700"><span class="font-semibold text-slate-900">Increment / Decrement:</span><br><code class="font-mono text-[10px]">count += 1</code> is shortcut for <code class="font-mono text-[10px]">count = count + 1</code></td></tr></tbody></table>
Dot, Comma, Underscore & Slicing
. Dot (Period)
Accesses functions inside libraries or object methods.
math.sqrt(16)
text.upper()
, Comma
Separates items in lists, tuples, dictionaries, & arguments.
[1, 2, 3]
print(a, b)
_ Underscore
Used in snake_case names. Python forbids spaces in variables!
high_score = 99
for _ in range(3):
[ : ] Slice Colon
Extracts slices: [start:stop:step] (stop is excluded!).
word[0:3] # 0,1,2
word[::-1] # reverse
Syntax Error Decoder: What Did You Forget? Common Terminal Errors
unexpected EOF while parsing
The Fix: You opened a bracket ( [ { or quote but reached the End Of File without closing it!
SyntaxError: invalid syntax at ":"
The Fix: You forgot the colon : at the end of your if, for, while, or def line.
cannot assign to expression / literal
The Fix: You wrote if score = 100: with a single = instead of double ==!
unterminated string literal
The Fix: You opened a string with " and tried to close it with ', or forgot the closing quote entirely.
Spot The Bug Can you find the missing punctuation? • if age >= 16 print("Drive")
Answer: Missing colon : after 16
Python Punctuation Quick Reference • Beginner Computer Science
Print front & back for best use