Python Classes and Recursion Flashcards
object
In programming, an object is a grouping of data (variables) and operations that can be performed on that data (functions or methods).
encapsulation
aka Abstraction / information hiding
when a user interacts with an object at a high level, allowing lower-level internal details to remain hidden (aka information hiding or encapsulation).
abstract data type / ADT
An abstract data type (ADT) is a data type whose creation and update are constrained to specific well-defined operations.
built-in
objects that Python automatically creates for a programmer to use and include the basic data types like integers and strings.
class
used to create a user-defined type of object containing groups of related variables and functions.
attributes
determines the data and behavior of the class for objects.
instantiation
Defining a new class variable by ‘calling’ the class, using parentheses like a function call as in my_time = Time().
instance
an individual object of the given class.
method
A method is a function defined within a class.
constructor
__init__
responsible for setting up the initial state of the new instance.
attribute reference operator /
member operator /
dot notation
Attributes can be accessed using the attribute reference operator ‘.’ (sometimes called the member operator or dot notation).
instance method
A function defined within a class is known as an instance method.
special method name
A special method name, indicating that the method implements some special behavior of the class, identified with the double underscore
__init__ - initializer/constructor
class object
A class object acts as a factory that creates instance objects.
instance object
When created by the class object, an instance object is initialized via the __init__ method.
class attribute
A class attribute is shared among all instances of that class.
instance attribute
An instance attribute can be unique to each instance.
class interface
A class interface consists of the methods that a programmer calls to create, modify, or access a class instance.
abstract data type (ADT)
A class can be used to implement the computing concept known as an abstract data type (ADT), whose creation and update are constrained to specific, well-defined operations (the class interface).
Class customization
Class customization is the process of defining how an instance of a class should behave for some common operations. Such operations might include printing, accessing attributes, or how instances of that class are compared to each other.
special method names
To customize a class, a programmer implements instance methods with special method names that the Python interpreter recognizes.
operator overloading
Class customization can redefine the functionality of built-in operators like <, >=, +, -, and * when used with class instances, a technique known as operator overloading.
rich comparison methods
Methods like __lt__ above are known as rich comparison methods.
isinstance()
To handle subtraction of arbitrary object types, the built-in isinstance() function can be used.