Python Lists: .lower() attribute error

后端 未结 2 1482
暖寄归人
暖寄归人 2021-01-28 09:12

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

2条回答
  •  [愿得一人]
    2021-01-28 09:17

    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]
    

提交回复
热议问题