Created
June 15, 2017 22:29
-
-
Save vijayanandrp/39e71f87d7e61ec69d79b36c7e4493f3 to your computer and use it in GitHub Desktop.
How to write Class in Python with examples
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
| #!/usr/bin/env python | |
| class Worker: | |
| def __init__(self, name, pay): | |
| self.name = name | |
| self.pay = pay | |
| def last_name(self): | |
| return self.name.split()[-1] | |
| def give_raise(self, percent): | |
| self.pay *= (1.0 + percent) | |
| def main(): | |
| bob = Worker('Bob Smith', 500000) | |
| sue = Worker('Sue Jones', 650000) | |
| print "Bob's last name is ", bob.last_name() | |
| print "Sue's last name is ", sue.last_name() | |
| sue.give_raise(0.1) | |
| print "Sue pay is ", sue.pay | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment