difference between string and list

skip at pobox.com skip at pobox.com
Tue Feb 27 15:28:54 EST 2007


    lincoln> strings have methods like string.count("f") returns 1.  What
    lincoln> methods do lists have?  Is it a similar class to string?

Similar in some ways, different in others.  Some things to play with:

    1. At an interpreter prompt, execute:

        help("")
        help([])

    2. Check the relevant sections of the tutorial:

        http://docs.python.org/dev/tut/node5.html#SECTION005120000000000000000
        http://docs.python.org/dev/tut/node5.html#SECTION005140000000000000000

Two significant differences:

    1. Strings are immutable.

    2. Lists can contain any kind of object, not just characters.

Skip



More information about the Python-list mailing list