Dunders

Class

Dunder MethodDescription
__init__Initializes a newly created instance of the class.
__str__Returns a string representation of the class instance.
__repr__Returns a string representation of the class instance for debugging.
__eq__Compares two class instances for equality using the == operator.
__ne__Compares two class instances for inequality using the != operator.

Function

Dunder MethodDescription
__call__Allows the function to be called as if it were a regular function.
__repr__Returns a string representation of the function.
__doc__Returns the docstring associated with the function.

Iterator

Dunder MethodDescription
__iter__Returns the iterator object itself.
__next__Retrieves the next item from the iterator.

Context Manager

Dunder MethodDescription
__enter__Returns the context manager itself or an object related to the context.
__exit__Defines the behavior when exiting the context manager.

Generator

Dunder MethodDescription
__iter__Returns the generator object itself.
__next__Retrieves the next generated value from the generator.

List

Dunder MethodDescription
__len__Returns the number of items in the list.
__getitem__Allows indexing and slicing of the list.
__setitem__Allows assignment to specific indices of the list.
__delitem__Allows deletion of specific indices from the list.
__iter__Returns an iterator object for the list.
__contains__Checks if an item is present in the list.
__add__Allows concatenation of two lists using the + operator.
__mul__Allows replication of the list using the * operator.
__eq__Compares two lists for equality using the == operator.
__ne__Compares two lists for inequality using the != operator.
__lt__Compares two lists for less than using the < operator.
__gt__Compares two lists for greater than using the > operator.
__le__Compares two lists for less than or equal to using the <= operator.
__ge__Compares two lists for greater than or equal to using the >= operator.

String

Dunder MethodDescription
__len__Returns the length of the string.
__getitem__Allows indexing and slicing of the string.
__setitem__Raises an error as strings are immutable.
__delitem__Raises an error as strings are immutable.
__iter__Returns an iterator object for the string.
__contains__Checks if a substring is present in the string.
__add__Concatenates two strings using the + operator.
__mul__Replicates the string using the * operator.
__eq__Compares two strings for equality using the == operator.
__ne__Compares two strings for inequality using the != operator.
__lt__Compares two strings lexicographically using the < operator.
__gt__Compares two strings lexicographically using the > operator.
__le__Compares two strings lexicographically using the <= operator.
__ge__Compares two strings lexicographically using the >= operator.

Tuple

Dunder MethodDescription
__len__Returns the number of items in the tuple.
__getitem__Allows indexing and slicing of the tuple.
__setitem__Raises an error as tuples are immutable.
__delitem__Raises an error as tuples are immutable.
__iter__Returns an iterator object for the tuple.
__contains__Checks if an item is present in the tuple.
__add__Concatenates two tuples using the + operator.
__mul__Replicates the tuple using the * operator.
__eq__Compares two tuples for equality using the == operator.
__ne__Compares two tuples for inequality using the != operator.
__lt__Compares two tuples lexicographically using the < operator.
__gt__Compares two tuples lexicographically using the > operator.
__le__Compares two tuples lexicographically

using the <= operator. __ge__ | Compares two tuples lexicographically using the >= operator.

Dictionary

Dunder MethodDescription
__len__Returns the number of key-value pairs in the dictionary.
__getitem__Allows accessing a value by key using indexing.
__setitem__Allows assigning a value to a key in the dictionary.
__delitem__Allows deleting a key-value pair from the dictionary.
__iter__Returns an iterator object for the dictionary keys.
__contains__Checks if a key is present in the dictionary.
__eq__Compares two dictionaries for equality using the == operator.
__ne__Compares two dictionaries for inequality using the != operator.

Set

Dunder MethodDescription
__len__Returns the number of elements in the set.
__contains__Checks if an element is present in the set.
__iter__Returns an iterator object for the set.
__eq__Compares two sets for equality using the == operator.
__ne__Compares two sets for inequality using the != operator.
__lt__Checks if the set is a proper subset of another set using the < operator.
__gt__Checks if the set is a proper superset of another set using the > operator.
__le__Checks if the set is a subset of another set using the <= operator.
__ge__Checks if the set is a superset of another set using the >= operator.

File

Dunder MethodDescription
__enter__Returns a context manager for the file.
__exit__Defines the behavior when exiting the context manager.
__iter__Returns an iterator object for reading lines from the file.

Integer

Dunder MethodDescription
__add__Performs addition with another integer using the + operator.
__sub__Performs subtraction with another integer using the - operator.
__mul__Performs multiplication with another integer using the * operator.
__divmod__Performs division with another integer and returns both quotient and remainder using the divmod() function.
__pow__Performs exponentiation with another integer using the ** operator.
__eq__Compares two integers for equality using the == operator.
__ne__Compares two integers for inequality using the != operator.
__lt__Compares two integers for less than using the < operator.
__gt__Compares two integers for greater than using the > operator.
__le__Compares two integers for less than or equal to using the <= operator.
__ge__Compares two integers for greater than or equal to using the >= operator.

Decimal

Dunder MethodDescription
__add__Performs addition with another decimal using the + operator.
__sub__Performs subtraction with another decimal using the - operator.
__mul__Performs multiplication with another decimal using the * operator.
__truediv__Performs division with another decimal using the / operator.
__floordiv__Performs floor division with another decimal using the // operator.
__mod__Performs modulus (remainder) operation with another decimal using the % operator.
__pow__Performs exponentiation with another decimal using the ** operator.
__eq__Compares two decimals for equality using the == operator.
__ne__Compares two decimals for inequality using the != operator.
__lt__Compares two decimals for less than using the < operator.
__gt__Compares two decimals for greater than using the > operator.
__le__Compares two decimals for less than or equal to using the <= operator.
__ge__Compares two decimals for greater than or equal to using the >= operator.

Date

Dunder MethodDescription
__str__Returns a string representation of the date.
__repr__Returns a string representation of the date for debugging.
__eq__Compares two dates for equality using the == operator.
__ne__Compares two dates for inequality using the != operator.
__lt__Compares two dates for less than using the < operator.
__gt__Compares two dates for greater than using the > operator.
__le__Compares two dates for less than or equal to using the <= operator.
__ge__Compares two dates for greater than or equal to using the >= operator.

Time

Dunder MethodDescription
__str__Returns a string representation of the time.
__repr__Returns a string representation of the time for debugging.
__eq__Compares two times for equality using the == operator.
__ne__Compares two times for inequality using the != operator.
__lt__Compares two times for less than using the < operator.
__gt__Compares two times for greater than using the > operator.
__le__Compares two times for less than or equal to using the <= operator.
__ge__Compares two times for greater than or equal to using the >= operator.

Datetime

Dunder MethodDescription
__str__Returns a string representation of the datetime.
__repr__Returns a string representation of the datetime for debugging.
__eq__Compares two datetimes for equality using the == operator.
__ne__Compares two datetimes for inequality using the != operator.
__lt__Compares two datetimes for less than using the < operator.
__gt__Compares two datetimes for greater than using the > operator.
__le__Compares two datetimes for less than or equal to using the <= operator.
__ge__Compares two dat

Regular Expression

Dunder MethodDescription
__init__Initializes a regular expression pattern.
__repr__Returns a string representation of the regular expression pattern.
__str__Returns a string representation of the regular expression pattern.
__eq__Compares two regular expression patterns for equality using the == operator.
__ne__Compares two regular expression patterns for inequality using the != operator.
__match__Matches the regular expression pattern against a string from the start.
__search__Searches for the regular expression pattern in a string.
__findall__Finds all occurrences of the regular expression pattern in a string.
__finditer__Returns an iterator yielding match objects for all occurrences of the regular expression pattern in a string.

Enum

Dunder MethodDescription
__str__Returns a string representation of the enum member.
__repr__Returns a string representation of the enum member for debugging.
__eq__Compares two enum members for equality using the == operator.
__ne__Compares two enum members for inequality using the != operator.
__lt__Compares two enum members for less than using the < operator.
__gt__Compares two enum members for greater than using the > operator.
__le__Compares two enum members for less than or equal to using the <= operator.
__ge__Compares two enum members for greater than or equal to using the >= operator.

Bytes

Dunder MethodDescription
__len__Returns the number of bytes in the bytes object.
__getitem__Allows indexing of the bytes object.
__setitem__Allows assignment to specific indices of the bytes object.
__iter__Returns an iterator object for the bytes object.
__contains__Checks if a byte value is present in the bytes object.
__add__Concatenates two bytes objects using the + operator.
__mul__Replicates the bytes object using the * operator.
__eq__Compares two bytes objects for equality using the == operator.
__ne__Compares two bytes objects for inequality using the != operator.
__lt__Compares two bytes objects lexicographically using the < operator.
__gt__Compares two bytes objects lexicographically using the > operator.
__le__Compares two bytes objects lexicographically using the <= operator.
__ge__Compares two bytes objects lexicographically using the >= operator.

Range

Dunder MethodDescription
__len__Returns the number of items in the range.
__getitem__Allows indexing of the range.
__iter__Returns an iterator object for the range.
__contains__Checks if a value is present in the range.
__eq__Compares two ranges for equality using the == operator.
__ne__Compares two ranges for inequality using the != operator.

Complex

Dunder MethodDescription
__abs__Returns the absolute value (magnitude) of the complex number.
__add__Performs addition with another complex number using the + operator.
__sub__Performs subtraction with another complex number using the - operator.
__mul__Performs multiplication with another complex number using the * operator.
__truediv__Performs division with another complex number using the / operator.
__eq__Compares two complex numbers for equality using the == operator.
__ne__Compares two complex numbers for inequality using the != operator.
__str__Returns a string representation of the complex number.
__repr__Returns a string representation of the complex number for debugging.

bytearray

Dunder MethodDescription
__len__Returns the number of elements in the bytearray.
__getitem__Allows indexing of the bytearray.
__setitem__Allows assignment to specific indices of the bytearray.
__iter__Returns an iterator object for the bytearray.
__contains__Checks if a value is present in the bytearray.
__add__Concatenates two bytearrays using the + operator.
__mul__Replicates the bytearray using the * operator.
__eq__Compares two bytearrays for equality using the == operator.
__ne__Compares two bytearrays for inequality using the != operator.
__lt__Compares two bytearrays lexicographically using the < operator.
__gt__Compares two bytearrays lexicographically using the > operator.
__le__Compares two bytearrays lexicographically using the <= operator.
__ge__Compares two bytearrays lexicographically using the >= operator.

memoryview

Dunder MethodDescription
__len__Returns the number of elements in the memoryview.
__getitem__Allows indexing of the memoryview.
__setitem__Allows assignment to specific indices of the memoryview.
__iter__Returns an iterator object for the memoryview.
__contains__Checks if a value is present in the memoryview.
__eq__Compares two memoryviews for equality using the == operator.
__ne__Compares two memoryviews for inequality using the != operator.
__str__Returns a string representation of the memoryview.
__repr__Returns a string representation of the memoryview for debugging.

frozenset

Dunder MethodDescription
__len__Returns the number of elements in the frozenset.
__contains__Checks if an element is present in the frozenset.
__iter__Returns an iterator object for the frozenset.
__eq__Compares two frozensets for equality using the == operator.
__ne__Compares two frozensets for inequality using the != operator.
__lt__Checks if the frozenset is a proper subset of another frozenset using the < operator.
__gt__Checks if the frozenset is a proper superset of another frozenset using the > operator.
__le__

| Checks if the frozenset is a subset of another frozenset using the <= operator. __ge__ | Checks if the frozenset is a superset of another frozenset using the >= operator.

Set

Dunder MethodDescription
__len__Returns the number of elements in the set.
__contains__Checks if an element is present in the set.
__iter__Returns an iterator object for the set.
__eq__Compares two sets for equality using the == operator.
__ne__Compares two sets for inequality using the != operator.
__lt__Checks if the set is a proper subset of another set using the < operator.
__gt__Checks if the set is a proper superset of another set using the > operator.
__le__Checks if the set is a subset of another set using the <= operator.
__ge__Checks if the set is a superset of another set using the >= operator.
__add__Performs set union with another set using the + operator.
__sub__Performs set difference with another set using the - operator.
__and__Performs set intersection with another set using the & operator.
__or__Performs set union with another set using the `
__xor__Performs set symmetric difference with another set using the ^ operator.

FrozenSet

Dunder MethodDescription
__len__Returns the number of elements in the frozenset.
__contains__Checks if an element is present in the frozenset.
__iter__Returns an iterator object for the frozenset.
__eq__Compares two frozensets for equality using the == operator.
__ne__Compares two frozensets for inequality using the != operator.
__lt__Checks if the frozenset is a proper subset of another frozenset using the < operator.
__gt__Checks if the frozenset is a proper superset of another frozenset using the > operator.
__le__Checks if the frozenset is a subset of another frozenset using the <= operator.
__ge__Checks if the frozenset is a superset of another frozenset using the >= operator.

Dict

Dunder MethodDescription
__len__Returns the number of key-value pairs in the dictionary.
__getitem__Allows indexing of the dictionary using keys.
__setitem__Allows assignment of values to keys in the dictionary.
__delitem__Allows deletion of keys and their corresponding values from the dictionary.
__contains__Checks if a key is present in the dictionary.
__iter__Returns an iterator object for the keys of the dictionary.
__eq__Compares two dictionaries for equality using the == operator.
__ne__Compares two dictionaries for inequality using the != operator.
__str__Returns a string representation of the dictionary.
__repr__Returns a string representation of the dictionary for debugging.

DefaultDict

Dunder MethodDescription
__len__Returns the number of key-value pairs in the defaultdict.
__getitem__Allows indexing of the defaultdict using keys.
__setitem__Allows assignment of values to keys in the defaultdict.
__delitem__Allows deletion of keys