43. Problem to create a Python class example

In this Python oops program, we will create a Python class example. Python class called Laptop with attributes brand, model, and storage.

Python class example

Steps to solve the program
  1. The Laptop class is defined with a constructor method __init__ that takes brand, model, and storage as parameters and initializes the instance variables self.brand, self.model, and self.storage with the provided values.
  2. The class also has three methods: start_up, shut_down, and check_storage_capacity.
    The start_up method simply prints a message indicating that the laptop is starting up.
  3. The shut_down method prints a message indicating that the laptop is shutting down.
  4. The check_storage_capacity method prints the storage capacity of the laptop in gigabytes.
  5. The code creates an object laptop of the Laptop class by calling its constructor and passing the brand “Dell”, model “XPS 13”, and storage capacity of 1000 as arguments.
  6. The start_up method is called on the laptop object to simulate starting up the laptop.
  7. The shut_down method is called on the laptop object to simulate shutting down the laptop.
  8. The check_storage_capacity method is called on the laptop object to display the storage capacity of the laptop.
  9. Thus, we have created a Python class example.
				
					class Laptop:
    def __init__(self, brand, model, storage):
        self.brand = brand
        self.model = model
        self.storage = storage
    
    def start_up(self):
        print("Starting up the laptop")
    
    def shut_down(self):
        print("Shutting down the laptop")
    
    def check_storage_capacity(self):
        print(f"Storage capacity: {self.storage}GB")

# Create an object of the Laptop class
laptop = Laptop("Dell", "XPS 13", 1000)
laptop.start_up()
laptop.shut_down()
laptop.check_storage_capacity()
				
			

Output:

				
					Starting up the laptop
Shutting down the laptop
Storage capacity: 1000GB
				
			

Related Articles

Create a Python class called Phone with attributes brand, model, and storage. 

Create a Python class called Book with attributes title, author, and pages.

Leave a Comment