|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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}
你现在贴的代码是没问题的,之前的有问题估计是因为你 title 方法后面没加括号。
|
|