Reputation: 4185
I know what the problem is, i just don't know how to fix it. I've googled how to make a class attribute into a string and I can't find anything. I know it's trying to add a class attribute to a string but how do I make self.mystring into a string so I can add strings together?
I put comments on what I thought was happening in my code. Thank you.
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
error message: cap = cap + sentence[0].upper + sentence[1:]
TypeError: cannot concatenate 'str' and 'builtin_function_or_method' objects
Upvotes: 0
Views: 278
Reputation: 8492
You need to add parens after upper
-- it's a method of string.
cap = cap + sentence[0].upper() + sentence[1:] #adding "" + capital letter + rest of sentence
Upvotes: 1