Beginner question: difference between lists and tuples

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KDawg44

    #1

    Beginner question: difference between lists and tuples

    Hi,

    I am trying to learn python. I am working through a tutorial on
    python.org. I am trying to figure out how lists are different than
    tuples other than changing values at specific indices. How are these
    different from arrays in other languages such as php?

    THanks.

  • Jim

    #2
    Re: Beginner question: difference between lists and tuples

    On Mar 14, 3:46 pm, "KDawg44" <KDaw...@gmail. comwrote:
    I am trying to learn python. I am working through a tutorial on
    python.org. I am trying to figure out how lists are different than
    tuples other than changing values at specific indices.
    You can change lists but not tuples. That has some advantages, as
    when you append to a list. But it has some disadvantages, as here
    where I can't use a list as the key in a hash.
    >>d={[1,2]:'a'}
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: list objects are unhashable
    >>d={(1,2):'a '}
    >>>
    Jim


    Comment

    • Bruno Desthuilliers

      #3
      Re: Beginner question: difference between lists and tuples

      KDawg44 a écrit :
      Hi,
      >
      I am trying to learn python. I am working through a tutorial on
      python.org. I am trying to figure out how lists are different than
      tuples other than changing values at specific indices.
      Contents: General Python FAQ- General Information- What is Python?, What is the Python Software Foundation?, Are there copyright restrictions on the use of Python?, Why was Python created in the fi...

      Comment

      Working...