我知道问题出在哪里,只是不知道如何解决。我用谷歌搜索了如何将类属性转换为字符串,但我找不到任何东西。我知道它正在尝试将类属性添加到字符串,但是如何将 self.mystring 转换为字符串,以便可以将字符串添加在一起?
我对我认为在我的代码中发生的事情发表了评论。谢谢你。
def capitalize(self):
cap = "" #initializing cap
sentence = str(self.mystring) #typecasting self.mystring into a string
cap = cap + sentence[0].upper + sentence[1:] #adding "" + capital letter + rest of sentence
return cap # returning the end result
错误信息:cap = cap + sentence[0].upper + sentence[1:]
TypeError:无法连接“str”和“builtin_function_or_method”对象