[Python] Mylist has an AttributeError when i was trying to capitalize it and find its length?

Discussão em 'Python' iniciado por Stack, Abril 21, 2025.

  1. Stack

    Stack Membro Participativo

    I want the following code to give me the title form and length of the list:

    mylist = ['clean the keyboard', 'meet tom', 'throw the trash']
    mylist.capitalize()

    for index, item in enumerate(mylist):
    row = f"{index + 1}.{item}"
    print(row.title())
    print(len(row))


    But instead of giving me the title of these todos and the length of the list it is giving me an attribute error.

    This is the following error:

    Traceback (most recent call last):
    File "C:\Users\tguru\Documents\todo_app\delete.py", line 2, in <module>
    mylist.capitalize()
    ^^^^^^^^^^^^^^^^^
    AttributeError: 'list' object has no attribute 'capitalize'


    I expect the code to give me the list's length and the list's title version.

    Continue reading...

Compartilhe esta Página