[問題] class執行結果

看板Python作者 (溫柔殺手)時間7年前 (2018/05/26 20:25), 編輯推噓0(003)
留言3則, 2人參與, 7年前最新討論串1/1
各位版上的大大晚上好 請教一下,下方程式為什麼兩個Print的結果會不一樣? class Banks(): title = 'Taipei Bank' def __init__(self,uname, money): self.name = uname self.balance = money def get_balance(self): return self.balance hungbank = Banks('hung',100) print(hungbank.name.title(),"存款是 ", hungbank.get_balance()) print(hungbank.name,"存款是 ", hungbank.get_balance()) 為什麼第一個出來的結果會是大寫? 我並沒有設定大寫的變數或功能。 在書上title被稱為是類別下的屬性,但卻對屬性沒有多加說明。 煩請高手解惑,感謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.195.98.141 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1527337557.A.1E5.html

05/26 21:20, 7年前 , 1F
title是str的方法
05/26 21:20, 1F

05/26 21:20, 7年前 , 2F

05/27 14:49, 7年前 , 3F
原來如此,感恩。
05/27 14:49, 3F
文章代碼(AID): #1R2L9L7b (Python)
文章代碼(AID): #1R2L9L7b (Python)