proffreda

Intro to Classes and Objects in Python

Mar 6th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. class Candidate:
  2.  
  3.     def __init__(self, name, website, twitter):
  4.         self.name = name
  5.         self.website = website
  6.         self.twitter = twitter
  7.  
  8.     def SayHello(self):
  9.         print("Hello, I'm " + self.name)
  10.         print("Please visit my website: " + self.website)
  11.         print("Or find me on twitter at: " + self.twitter)
  12.  
  13.     def SetName(self, name):
  14.         self.name = name
  15.  
  16.  
  17. if __name__ == "__main__":
  18.     hillary = {'name':'Hillary Clinton',
  19.                'website':'http://hillaryclinton.com',
  20.                'twitter':'http://twitter.com/HillaryClinton'}
  21.     print(hillary['name'])
  22.     print(hillary['website'])
  23.     print(hillary['twitter'])
  24.    
  25.     bernie= Candidate("Bernie Sanders",
  26.                       "http://berniesanders.com",
  27.                       "http://twitter.com/BernieSanders")
  28.     bernie.SayHello()
Advertisement
Add Comment
Please, Sign In to add comment