Abir Palekar - Chapter 8 Notesheet
Abir Palekar - Chapter 8 Notesheet
Enduring Understanding:
Introductions of OOP and making User defined classes.
.
Targets:
● Make User defined classes.
Outline Notes
Understanding Object-Oriented Basics
Page 219 a programming paradigm that is based on the concept of objects, which can contain data
understanding Object- and code that manipulates that data
Oriented Basics
Creating Classes, Creating a new class creates a new type of object, allowing new instances of that type to
Methods and Objects be made. Each class instance can have attributes attached to it.
Defining a Class Classes provide a means of bundling data and functionality together. Creating a new class
creates a new type of object.
defining a Method is a label that you can call on an object; it is a piece of code to execute on that object.
Instantiating an Object creating an instance of a class. When you create an instance of a class, you instantiate the
object.
Invoking a Method Helps you run a specified method from a Python script directly in a workflow.
Using Constructors
Using Constructors initializeI(assign values) to the data members of the class when an object of the class is
created
Creating a Constructor constructor is a special type of method (function) which is used to initialize the instance
members of the class.
Creating Multiple We can create a list of objects in Python by appending class instances to the list.
Objects
Using Attributes
Page 226 The python __init__ method is declared within a class and is used to initialize the attributes
Initializing Attributes of an object as soon as the object is formed.
Accessing Attributes Attributes of a class are function objects that define corresponding methods of its
instances.
Printing an Object The dir() function is a built-in Python function that can also be used to list all the attributes
and methods of an object.
Using Class Attributes and Static Methods
Page 228 Class methods can access and modify class-level attributes. They have access to the
Using Class Attributes class object and can modify class variables or create new instances of the class.
and Static Methods
Page 230 Inside a class, you should qualify all references to class attributes with the class name
Creating a Class
Attribute
Page 231 To make a method a static method, add @staticmethod decorator before the method
Creating a Static definition
Method
Page 232 You can call a static method directly from the class, without having to create an object of
Invoking a Static Method the class first.
Page 238 You can create a property by calling property() with an appropriate set of arguments and
Creating Properties assigning its return value to a class attribute.
Page 240 Attributes of a class can also be accessed using the following built-in methods and
Accessing Properties functions.