From 155b48f5bd82e07b9c2c2f9f1bd30f7810893cf5 Mon Sep 17 00:00:00 2001 From: kjg Date: Wed, 10 Jun 2020 22:37:13 +0900 Subject: [PATCH] [Python #8] create e40.py --- kjg/python-the-hard-way/e40.py | 20 ++++++++++++++++++++ kjg/python.org | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 kjg/python-the-hard-way/e40.py diff --git a/kjg/python-the-hard-way/e40.py b/kjg/python-the-hard-way/e40.py new file mode 100644 index 0000000..31f5dbe --- /dev/null +++ b/kjg/python-the-hard-way/e40.py @@ -0,0 +1,20 @@ +class Song(object): + def __init__(self, lyrics): + self.lyrics = lyrics + + def sing_me_a_song(self): + for line in self.lyrics: + print(line) + + +ly1 = ["Happy birthday to you", "I don't want to get sued", "So I'll stop right there"] +ly2 = ["They rally around tha family","With pockets full of shells"] + +happy_bday = Song(ly1) + +bulls_on_parade = Song(ly2) + + +happy_bday.sing_me_a_song() + +bulls_on_parade.sing_me_a_song() diff --git a/kjg/python.org b/kjg/python.org index 66ab96d..e8ae276 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -142,3 +142,6 @@ analysis sample codes append list **** ex39 How to use dictionary +*** Python #8 +**** ex40 +How to use class