可能重複:
Python: How to print a class or objects of class using print()?如何在python中打印/返回一個類?
我現在有這樣的代碼:
class Track(object):
def __init__(self,artist,title,album=None):
self.artist = artist
self.title = title
self.album = album
def __str__(self):
return self.title + self.artist + self.album
現在,當我把類似Track('Kanye West','Roses','Late Registration')
到終端我得到<__main__.Track object at 0x10f3e0c50>
我怎樣才能得到它返回或打印該地點的價值?
我是新來的編程,尤其是新的'面向對象編程',所以我的問題是什麼是一個類?我如何在一個類中定義一個函數?
嘗試'str(Track('Kanye West','Roses','Late Registration'))' –
搜索優先:http://stackoverflow.com/questions/1535327/python-how-to-print-a -class-or-objects-of-class-using-print –
我嘗試過搜索,但我仍然有點困惑,我想我正在尋找更多日常用語的解釋。 – iamtesla