0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.