Python ?class合集

16.class it up
inside the Triangleclass:
1.create a variable named number_of_sidesand set it equal to 3.
2.create a method named return Trueif the sum of self.angle1,self.angle2,and self.angle3is equal 180,and False otherwise.
Hint:
the check_anglesmethod should look something like this:
def check_angles(self):
if self.angle1 +self.angle2 +self.angle3 == 180:
return True
else:
return False

17.instantiate an object
1.create a variable named my_triangleand set it equal to a new instance of your Triangle class.Pass it three angles that sum to 180(eg.90,30,60)
2.print out my_triangle.number_of_sides
3.print out my_triangle.check_angles()

Hint:
remember,we can instantiate an object like so:
instance = class(args)
whereargs are the arguments init__() takes,not including self

18.inheritance
1.create a class named Equilateral that inherits from Triangle
2.inside Equilateral,create a member variable named angle and set it equal to 60
3.create an init() function with only the parameter self ,and self .angle1,self.angle2,and self.angle3 equal to self.angle(since an equilateral triangle's angles will always be 60)

class Triangle(object):
def init(self,angle1,angle2,angle3):
self.angle1 =angle1
self.angle2 = angle2
self.angle3 = angle3
number_of_sides = 3
def check_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
else:
return False
my_triangle = Triangle(90,60,30)
print my_triangle.number_of_sides
print my_triangle.check_angles()
class Equilateral(Triangle):
angle = 60
def init(self):
self.angle1 =self.angle
self.angle2 = self.angle
self.angle3 = self.angle

5.instantiating your first object
class Square(object):
def init__(self):
self.sides = 4
my_shape = Square()
print my_share.sides
1.first,we create a class named Square with an attribute sides.
2.outside the class definition,we create a new instance of square named my_shape and access that attribute using my_shape.sides.

8.a methodical approach
your method should look something like this:
def description(self):

前面有篇文章有詳細完整細節(jié)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市聪蘸,隨后出現(xiàn)的幾起案子笆包,更是在濱河造成了極大的恐慌,老刑警劉巖市袖,帶你破解...
    沈念sama閱讀 219,188評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件寥院,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機陌兑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來由捎,“玉大人兔综,你說我怎么就攤上這事∧辏” “怎么了软驰?”我有些...
    開封第一講書人閱讀 165,562評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長为居。 經(jīng)常有香客問我碌宴,道長,這世上最難降的妖魔是什么蒙畴? 我笑而不...
    開封第一講書人閱讀 58,893評論 1 295
  • 正文 為了忘掉前任贰镣,我火速辦了婚禮呜象,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘碑隆。我一直安慰自己恭陡,他們只是感情好,可當我...
    茶點故事閱讀 67,917評論 6 392
  • 文/花漫 我一把揭開白布上煤。 她就那樣靜靜地躺著休玩,像睡著了一般。 火紅的嫁衣襯著肌膚如雪劫狠。 梳的紋絲不亂的頭發(fā)上拴疤,一...
    開封第一講書人閱讀 51,708評論 1 305
  • 那天,我揣著相機與錄音独泞,去河邊找鬼呐矾。 笑死,一個胖子當著我的面吹牛懦砂,可吹牛的內(nèi)容都是我干的蜒犯。 我是一名探鬼主播,決...
    沈念sama閱讀 40,430評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼荞膘,長吁一口氣:“原來是場噩夢啊……” “哼罚随!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起羽资,我...
    開封第一講書人閱讀 39,342評論 0 276
  • 序言:老撾萬榮一對情侶失蹤淘菩,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后削罩,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體瞄勾,經(jīng)...
    沈念sama閱讀 45,801評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡费奸,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,976評論 3 337
  • 正文 我和宋清朗相戀三年弥激,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片愿阐。...
    茶點故事閱讀 40,115評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡微服,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出缨历,到底是詐尸還是另有隱情以蕴,我是刑警寧澤,帶...
    沈念sama閱讀 35,804評論 5 346
  • 正文 年R本政府宣布辛孵,位于F島的核電站丛肮,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏魄缚。R本人自食惡果不足惜宝与,卻給世界環(huán)境...
    茶點故事閱讀 41,458評論 3 331
  • 文/蒙蒙 一焚廊、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧习劫,春花似錦咆瘟、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至谤狡,卻和暖如春灸眼,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背墓懂。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評論 1 272
  • 我被黑心中介騙來泰國打工幢炸, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人拒贱。 一個月前我還...
    沈念sama閱讀 48,365評論 3 373
  • 正文 我出身青樓宛徊,卻偏偏與公主長得像,于是被迫代替她去往敵國和親逻澳。 傳聞我的和親對象是個殘疾皇子闸天,可洞房花燭夜當晚...
    茶點故事閱讀 45,055評論 2 355

推薦閱讀更多精彩內(nèi)容

  • #1996 AHSME ##1996 AHSME Problems/Problem 1 The addition ...
    abigtreenj閱讀 1,396評論 0 0
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,511評論 0 23
  • 對英語恨之入骨的痛,大概從第一次重視英語之后就埋下了痛根斜做。 從小學六年級畢業(yè)后的補習苞氮,一直補習補到了高中畢業(yè),每一...
    禾必閱讀 178評論 2 1
  • 文 | 周大漁 前兩天,表弟給我打電話霸旗,說他準備要來上海找工作贷帮,之前的工作已經(jīng)辭了。待會兒就買來上海的火車票诱告。讓我...
    周大漁可持續(xù)發(fā)展閱讀 319評論 0 0
  • $函數(shù) 綁定事件 click方法顯示隱藏——show撵枢、hide方法 hover方法解決函數(shù)中的this問題call...
    大捕獵店閱讀 320評論 0 0