Created
May 2, 2018 13:05
-
-
Save Roman-Port/c313104cb4e6a2b0a4f973db45d8db40 to your computer and use it in GitHub Desktop.
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
class CoolClass: | |
def __init__(self,name,description,price): | |
self.name = name | |
self.description = description | |
self.price = price | |
def ToString(self): | |
#Create a string of that object | |
output = "=[ " | |
output+=self.name | |
output+=" ]===" | |
output+="\nPrice: $"+str(self.price) | |
output+="\nDescription: " | |
output+= self.description | |
return output | |
def __str__(self): | |
#This is called when you print this object. | |
return self.ToString() #Return data from our ToString function. This could be done here | |
def __repr__(self): | |
return self.ToString() | |
#Testing the class | |
obj = CoolClass("Pear","A very fancy pear.",300) | |
print(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment