AttributeError: 'str' object has no attribute 'toLowerCase'

The Python str class does not contain a method named toLowerCase. The method that you are looking for is lower.

When you are faced with such an error message, the first thing you should do is to see what the class in question can do.

>>> s = 'some string'
>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__'
, '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul_
_', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__'
, '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_m
ap', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'ist
itle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition
', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

As you can see, toLowerCase is not here. But you can also see lower which should steer you in the right direction. And don't be afraid to look in the documentation which is invariably of excellent quality.


Use str.lower() instead.

fifth_word = input("Please enter your 1st word: ")
fifth_word = fifth_word.lower()
fourth_word = input("Please enter your 2nd word: ")
fourth_word = fourth_word.lower()
third_word = input("Please enter your 3rd word: ")
third_word = third_word.lower()
second_word = input("Please enter your 4th word: ")
second_word = second_word.lower()
first_word = input("Please enter your 5th word: ")
first_word = first_word.capitalize()
print("The sentence is: " + first_word + second_word + third_word + fourth_word + fifth_word)

Tags:

Python