Last active
May 23, 2020 01:40
-
-
Save Joelfranklin96/55362b2a5267eeeb0c63676b4672b299 to your computer and use it in GitHub Desktop.
class1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defining the class 'shirts' | |
class shirts: | |
# Initializing the attributes of the class | |
def __init__(self,color,size,price): | |
self.color = color | |
self.size = size | |
self.price = price | |
# Defining the methods | |
def change_color(self, new_color): | |
self.color = new_color | |
def change_size(self, new_size): | |
self.size = new_size | |
def double_price(self): | |
self.price = 2 * self.price | |
# Creating an object 'shirt1' | |
shirt1 = shirts('red',32,500) | |
# Printing the attributes of 'shirt1' | |
print(shirt1.color) | |
print(shirt1.size) | |
print(shirt1.price) | |
# Performing methods on the object | |
shirt1.change_color('yellow') | |
shirt1.change_size(28) | |
shirt1.double_price() | |
# Printing the new attributes of 'shirt1' | |
print(shirt1.color) | |
print(shirt1.size) | |
print(shirt1.price) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment