Python day 20:
If there is one song in the world that I can sing in tune, that is “Leo” 狮子座. It is the end of July now, let’s make a little Python program to print the lyrics of Leo.
Background Knowledge:
Class: take a grouping of functions and data for new thing and place them inside a container
Object: the most basic kind of thing, or any instance of some thing
Def: how to define a function inside a class
Example:
class X(Y) “Make a class named X that is-a Y”
class X(object): def init (self,J) :
“class X has a init that take self and J parameters”
Code:
LEO 狮子座
class song(object): def __init__(self,lyrics): self.lyrics=lyrics def sing_a_song(self): for line in self.lyrics: print(line) leo=song(["七月份的尾巴你是狮子座,八月份的前奏你是狮子座"]) leo.sing_a_song()
七月份的尾巴你是狮子座,八月份的前奏你是狮子座
忘羡
now let’s try one of my favorite songs in 2020, wuji 无羁/忘羡
wuji=song(["山高水远,又闻琴响,陈情未绝,卧荻花月如霜,煮一壶生死悲欢祭少年郎,明月依旧何来怅惘,不如潇潇洒洒历遍风和浪,天涯一曲共悠扬"]) wuji.sing_a_song()
山高水远,又闻琴响,陈情未绝,卧荻花月如霜, 煮一壶生死悲欢祭少年郎,明月依旧何来怅惘, 不如潇潇洒洒历遍风和浪,天涯一曲共悠扬
Happy practicing!
快点去练琴了,不然蓝2会嫌音不准 哈哈哈哈…
Ref:
Learn python the hard way
https://drive.google.com/file/d/0B-hV1HrMP8j1OWpEWXBXbUJsNms/view