For a function definition you'd speak of the "arguments" or "signature" of the function but is there a similar name for the list of parent classes and keyword arguments (since __init_subclass__
) that can be used for classes? How could I refer to this when writing documentation?
# Parameters, arguments, function signature
# v----------v
def func(arg1, arg2):
pass
# Similarly, what's this called?
# v-----------------------------v
class Cls(Parent, Mixin, mixin_arg=True):
pass
The parentheses in class definitions are for defining from which class you inherit. You don't write def in front of it, and when you inherit from 'object' which is the default you don't need the parentheses for the definition.
Empty parentheses mean that the function you are calling takes no arguments or it has default arguments pre-defined. When a function is part of a class, we call it "method". Example: Python has a built-in class called str (string), to represent a sequence of characters.
Python is an object oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.
To call a function within class with Python, we call the function with self before it. We call the distToPoint instance method within the Coordinates class by calling self. distToPoint . self is variable storing the current Coordinates class instance.
From my Python manual's specification for a class definition, perhaps we should call it the inheritance argument list:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With