Last active
December 31, 2019 19:04
-
-
Save JonyBepary/6de15f74c6e889eabe19682339492c17 to your computer and use it in GitHub Desktop.
New Year Greeting (OOP).
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
| # Author: Jony Bepary | |
| # Python Object-Oriented Programming | |
| # A function/data associate with class | |
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| # in class : | |
| # method = function | |
| # data/variable = Attribute | |
| # builtin library | |
| import datetime | |
| # A Class | |
| class Greet(object): | |
| """docstring for Greet For New Year""" | |
| # Init/magic/super function / Constructor | |
| def __init__(self, year, month, day): | |
| # Instance attributes / Variable | |
| self.year = year | |
| self.month = month | |
| self.day = day | |
| # Class fucntion / method | |
| def greet_msg(self): | |
| if self.day and self.day: | |
| print("Happy New Year //~~~> {0}".format(self.year)) | |
| # Class object assignment | |
| t = datetime.datetime.now() | |
| kal = Greet(t.year, t.month, t.day) | |
| if __name__ == '__main__': | |
| kal.greet_msg() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment