Classes In Python
1. CREATING AND USING A CLASS
1.1. Creating a Class
class Restaurant():
""" A class to store two attributes of a restaurant and have two methods (behaviors)"""
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(f"{self.restaurant_name.title()} serves {self.cuisine_type.title()} food.")
def open_restaurant(self):
print(f"{self.restaurant_name.title()} is open now.")1.2. Making instances of Class
a. Making instance
b. Accessing Attributes
c. Calling Methods
d. Output
2. WORKING WITH CLASSES AND INSTANCES
2.1. Setting a Default Value for an Attribute
2.2. Modifying Attribute Values
a. Modifying an Attribute Value Directly
b. Modifying an attributeβs Value through a Method
c. Incrementing an attributeβs Value through a Method
3. INHERITANCE
3.1. Creating Child Class from Parent Class
a. Creating Child Class
b. Creating Instance of Child Class
3.2. Overwriting Methods from the Parent Class
3.3. Instances as Attributes
4. IMPORTING CLASSES
4.1. Importing a Single Class
a. Syntax to import
b. Syntax to create instance
4.2. Importing Multiple Classes from a Module
a. Syntax to import
b. Syntax to create instance
4.3. Importing an Entire Module
a. Syntax to import
b. Syntax to create instance
4.4. Importing All Classes from a Module
a. Syntax to import
b. Syntax to create instance
4.5. Importing a Module into a Module
Last updated