所以我通过Python崩溃了,我不明白为什么这样做没有正确的方法:
>favorite_numbers = {
'mike': 15,
'john': 97
}
print("Mike's favorite number is " + favorite_numbers['mike'].title() + ".")
print("John's favorite number is " + favorite_numbers['john'].title() + ".")
显示为:
'int'对象没有属性'title'
我缺少一些语法吗?我完全按照书中所说做。很抱歉这是一个初学者,但我想真正地理解我。
答案 0 :(得分:0)
尝试一下。目前尚不清楚您要对“ favourite_numbers”的两个引用使用“ .title()”做什么。不仅不需要,而且不正确。
>favorite_numbers = {
'mike': 15,
'john': 97
}
print("Mike's favorite number is " + favorite_numbers['mike'] + ".")
print("John's favorite number is " + favorite_numbers['john'] + ".")