Instance method uses instance offset
Input
Adder(5).add(2)
Output
7
Instance method add accesses self.offset and returns offset + x.
Full lesson preview
Explore differences between instance methods and static methods: how they access instance data, and how they're called.
Problem statement
Task
Examples
Input
Adder(5).add(2)
Output
7
Instance method add accesses self.offset and returns offset + x.
Input
Adder.add_static(3, 4)
Output
7
Static methods behave like plain functions attached to the class; they don't receive self.
Input format
Output format
Constraints
Samples
Input
instance_add(3, 4)
Output
7
Creates Adder with offset 3 and adds 4 -> 7