Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with self
#2
Writing an add method does not override the + operator. You need to write an __add__ method (with two underscores before and after the name, this is called a dunder method). The parameters of the method will be self and other. So if you have two objects of the class C1 and C2, and do C1 + C2, that will call C1.__add__(C2), with C1 automatically assigned to the self parameter and C2 assigned to the other parameter.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Need help with self - by msp1981 - Apr-21-2019, 07:15 PM
RE: Need help with self - by ichabod801 - Apr-21-2019, 07:24 PM
RE: Need help with self - by msp1981 - Apr-21-2019, 08:56 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020