Skip to content

Instantly share code, notes, and snippets.

@Roman-Port
Created May 2, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roman-Port/c313104cb4e6a2b0a4f973db45d8db40 to your computer and use it in GitHub Desktop.
Save Roman-Port/c313104cb4e6a2b0a4f973db45d8db40 to your computer and use it in GitHub Desktop.
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