In this Python oops program, we will create a Python class example. Python class called Phone with attributes brand, model, and storage.
Python class example
Steps to solve the program
- The Phone 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.
- The class also has three methods: make_call, send_text_message, and check_storage_capacity.
- The make_call method takes a number as a parameter and prints a message indicating that a call is being made to that number.
- The send_text_message method takes a number and a message as parameters and prints a message indicating that a text message is being sent to the specified number with the provided message.
- The check_storage_capacity method prints the storage capacity of the phone in gigabytes.
- The code creates an object phone of the Phone class by calling its constructor and passing the brand “Apple”, model “iPhone 14”, and storage capacity of 256 as arguments.
- The make_call method is called on the phone object to simulate making a call to the number “1234567890”.
- The send_text_message method is called on the phone object to simulate sending a text message to the number “1234567890” with the message “Hello!”.
- The check_storage_capacity method is called on the phone object to display the storage capacity of the phone.
- Thus, we have created a Python class example.
Output:
Related Articles
Create a Python class called Laptop with attributes brand, model, and storage.
Create a Python class called Book with attributes title, author, and pages.
Create a Python class called EBook that inherits from the Book class.
Create a Python class called ShoppingCart with attributes items and total_cost.
Create a Python class called Animal with attributes name and color.
Create a Python class called Dog that inherits from the Animal class.