The error occurs because names
is a list, and lists in Python do not have a .capitalize()
method. The .capitalize()
method is only available for strings.
See the str.capitalize()
method being under the String methods section in the official Python documentation.