I am trying to create a program on python to do with manipulating lists/arrays. I am having trouble with an error:
lowercase = names.lower
Like the error message says, you can't use .lower()
on lists, only on strings. That means you'll have to iterate over the list and use .lower()
on every list item:
lowercase = [x.lower() for x in names]
The variable names
is a list. You can't use the .lower()
method on a list.
pp_ provided the solution:
lowercase = [x.lower() for x in names]
While not exactly equivalent to the previous example, this may read better to you and has, effectively, the same result:
lowercase=[]
for name in names:
lowercase.append(name.lower())
Alternate solution that may fit your needs:
print (str(names).lower())