0

I have seen many people use dunder variables(variables wrapped by __) like below.

class NumberService(object):
    __small__ = {
        'zero': 0,
        'one': 1,
        'two': 2,
        'three': 3,
        'four': 4,
                }

    __magnitude__ = {
        'thousand':     1000,
        'million':      1000000,
        'billion':      1000000000,
    }

    __ordinals__ = {
        'first': 'one',
        'second': 'two',
        'third': 'three',
        'fourth': 'four',

    }

    __fractions__ = {
        'quarter': 'four',
        'half': 'two',
        'halve': 'two'
    }

I am not able to figure out, what they mean exactly in python. I have come across magic methods, Is there any relation between these variables and magic methods?

user3415910
  • 440
  • 3
  • 5
  • 19
  • I disagree this is a dupe. Name mangling variables (the `__stuff1` in the other post) is only for variables with **at most a single trailing 1_`**. These look like builtins but they are not. – kabanus Feb 16 '18 at 10:28
  • To Op, can you post where you found this? `__func__` syntax is reserved for operators and built-ins usually, but for arbitrary function names it may be dependent on some convention of the author. – kabanus Feb 16 '18 at 10:31
  • Some of my colleague(left my company), has used this syntax. – user3415910 Feb 16 '18 at 10:36
  • Probably just wanted to mark these attributes special for some reason, I don't think it's something to do with Python itself beyond naming convention. – kabanus Feb 16 '18 at 10:53

0 Answers0