Lesson 38 of 55
8 mins readPython Colon Syntax (:) & The self Parameter
In Plain English
The colon operator `:` is syntactic sugar that automatically passes the object as the first parameter `self`. `obj:method(a, b)` is equivalent to `obj.method(obj, a, b)`.
Deep Dive: How It Works
Method Call Sugar: `obj:func(x)` expands to `obj.func(obj, x)`.
Method Definition Sugar: `function Class:func(x)` automatically defines `self` as the hidden first argument.
Clean Ergonomics: Eliminates repetitive `self` arguments at every method invocation.
Core Rules to Remember

Colon (:) Passes self: `a:b()` passes `a` as the first argument.

Defining with Colon: `function Class:method()` implicitly declares `self`.
Live Interactive Example
Hit Run Code to see it liveComparing Dot and Colon Invocations
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: c:increment(5) passed c as self automatically.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Define Method with Colon Syntax
Define a table `local Hero = { hp = 100 } Hero.__index = Hero`.
Add `function Hero:heal(pts) self.hp = self.hp + pts end`.
Call `Hero:heal(25)` and print `"Hero HP: " .. Hero.hp`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.