Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Built-in Namespace

Cindy on April 12, 2022

Hi Johan, thank you for the lecture. I am wondering what is the function of __ (dundas) in Python? And could you explain about the syntax: __builtins__.str.__module__?

Bartosz Zaczyński RP Team on April 13, 2022

@Cindy The word “dunder” is a common abbreviation for “double underscore” or __, which has a few special meanings in Python. In most cases, it’s used as a prefix and a suffix in special method names, such as .__str__() or .__len__(), to make them visually distinguishable from your own methods. When used as a prefix on your custom methods, the double underscore enables the name mangling mechanism, which has a purpose in multiple-inheritance scenarios.

__builtins__ is a special module that contains all Python built-in functions, types, etc. that you don’t typically need to import:

>>> type(__builtins__)
<class 'module'>

>>> __builtins__
<module 'builtins' (built-in)>

>>> __builtins__.len("Hello")
5

>>> len("Hello")
5

For example, you can call the global len() function directly or more explicitly by prefixing its name with the __builtins__ module it belongs to.

__module__ is an attribute containing the name of the module:

>>> len.__module__
'builtins'

>>> __builtins__.len.__module__
'builtins'

Become a Member to join the conversation.