3

I'm trying to figure out the proper name for these properties which are written using underscores, so that I can read about them and understand them more. They seem to generally be lower level things, more advanced stuff for really explicit behavior.

What terminology is used for these underscore properties/methods?

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220

3 Answers3

2

"Magic methods" is a term often used for those that are methods. "Double-underscore" is also sometimes used.

PEP 8 describes them as "magic".

BrenBarn
  • 242,874
  • 37
  • 412
  • 384
2

"Magic Methods". You can learn more about them here: http://docs.python.org/2/reference/datamodel.html#basic-customization

Important ones are:

  • __init__(): Constructor for a class
  • __str__() (or __unicode__(): verbose name of the object used whenever string conversion is needed (e.g. when calling print my_object

I'd say those are the one you'll need in the beginning.

OBu
  • 4,977
  • 3
  • 29
  • 45
1

Dunder. e.g. __init__ can be referred to as "dunder init". See this alias.

Marcin
  • 48,559
  • 18
  • 128
  • 201
Graeme Stuart
  • 5,837
  • 2
  • 26
  • 46