关于代码运行
def make_album(singer_name, album_name, song_number=""):singer_album = {
"Singer's name": singer_name.title(),
"Album name": album_name.title(),
}
if song_number:
singer_album["song numbers"] = song_number
return singer_album
singer_01 = make_album("leslie cheung", "red")
print(singer_01)
singer_02 = make_album("david bowie", "aladdin sane", 10)
print(singer_02)
singer_03 = make_album("hugh laurie", "let them talk", song_number=10)
print(singer_03)
为什么代码运行结果是这样
{"singer's name": 'Leslie Cheung', 'Album_name': <built-in method title of str object at 0x00000192F847CEB0>}
{"singer's name": 'David Bowie', 'Album_name': <built-in method title of str object at 0x00000192F847CF30>, 'song numbers': 10}
{"singer's name": 'Hugh Laurie', 'Album_name': <built-in method title of str object at 0x00000192F847CF70>, 'song numbers': 10}
本帖最后由 BSOD 于 2020-10-10 22:33 编辑
你需要贴出完整的代码, 给一部分没法看出问题, 至少要提供Album_name的构造类 你现在贴的代码是没问题的,之前的有问题估计是因为你 title 方法后面没加括号。
页:
[1]