42. Problem to create a Python class example

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
  1. 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.
  2. The class also has three methods: make_call, send_text_message, and check_storage_capacity.
  3. The make_call method takes a number as a parameter and prints a message indicating that a call is being made to that number.
  4. 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.
  5. The check_storage_capacity method prints the storage capacity of the phone in gigabytes.
  6. 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.
  7. The make_call method is called on the phone object to simulate making a call to the number “1234567890”.
  8. 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!”.
  9. The check_storage_capacity method is called on the phone object to display the storage capacity of the phone.
  10. Thus, we have created a Python class example.

Output:

Related Articles

Create a Python class called VIPCustomer that inherits from the Customer class.

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

Leave a Comment