Error using Lower(), upper() and title() functions

Asked

Viewed 267 times

0

I have the following problem, when trying to use the functions lower(), title() and upper().

My compiler simply won’t allow and displays the error

AttributeError:'list' object has no attribute'upper'

Follows the code:

bomdia = ["list"]
bomdia2 = ["LIST"]

print(bomdia.upper())#AttributeError:'list' object has no attribute'upper'
print(bomdia2.lower())#AttributeError:'list' object has no attribute'lower'
print(bomdia.title())#AttributeError: 'list' object has no attribute 'title'

1 answer

2


Your mistake is declaring as a list the variables bomdia and bomdia2

By declaring this way you are declaring a list of string’s and the upper, Lower and title methods are string methods, so the error #AttributeError:'list' object has no attribute'upper'.

You can resolve your error in these 2 ways:

  • Continue declaring as lists and access the string within that list:

    bomdia = ["list"]
    bomdia2 = ["LIST"]
    
    print(bomdia[0].upper())
    print(bomdia2[0].lower())
    print(bomdia[0].title())
    
  • Declare variables as string

    bomdia = "list"
    bomdia2 = "LIST"
    
    print(bomdia.upper())
    print(bomdia2.lower())
    print(bomdia.title())
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.