Object-oriented programming (OOP) is a method of structuring a program by bundling related properties and behaviors into individual objects
An object contains data, like the raw or preprocessed materials at each step on an assembly line, and behavior, like the action each assembly line component performs.
Class
Classes are used to create user-defined data structures. Classes define functions called methods, which identify the behaviors and actions that an object created from the class can perform with its data.
All class definitions start with the
class keyword, which is followed by the name of the class and a colon. Any code that is indented below the class definition is considered part of the class’s body.
Note: The body of the Dog class consists of a single statement: the pass keyword. pass is often used as a placeholder indicating where code will eventually go. It allows you to run this code without Python throwing an error.
__init__() sets the initial state of the object by assigning the values of the object’s properties. That is, .__init__() initializes each new instance of the class.
Comments
Post a Comment