OOP in Python Flashcards
Object-oriented programming
A programming paradigm based on “objects,” which contain state (attributes) and behavior (methods)
Object对象
A collection of structured data along with the operations that can be performed on that data. An object is one instance of a class.
Class类
A template or blueprint used to create objects of a specific data type. Defines what concrete objects will look like.
Instance实例
One particular object of a certain data type/class. Follows the format defined by its class, and has specific, individual state.
State状态
A generic term for the data that an object “knows” at one point in time. Usually, state can change over time.
Attribute属性
A named property of a class. Attributes are used to keep track of state.
Behavior行为
A generic term for what an object can “do.”
Method方法
A function that is defined inside of a class. Methods are usually used to describe behavior.
Constructor构造函数
A method used when creating objects. Usually initializes an object’s attributes.
__init__
Name of the method used by Python as the constructor. Pronounced “dunder init.” One of many “dunder” (double underscore) methods that are reserved by Python for specific tasks. Because __init__ is so common, the “dunder” is often dropped in spoken conversation.
self
The conventional name for a parameter that refers to an instance itself within a method of a class.
Module
Any .py file that contains functions, classes, variables, and/or other runnable code
Package
A collection of modules
Inheritance继承
A class relationship in which one class inherits attributes and behavior from another class. is-a relationship
Composition组合
A class relationship in which a class references other classes as instance variables and makes use of their methods and attributes. has-a relationship