A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

What is the difference between a list and a tuple?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://news.e-scribe.com/397

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think that a list is a set of elements that can be numbers or strings, or a subset. a tuple is a sequence of instructions.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    One functional aspect is that a list is mutable and a tuple is not.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The principal difference is this: a tuple is very much like a list except that it is immutable (i.e. it can't be changed). Both are object types and can be used for grouping data into a single object. Before looking at how they are different let's look at how they are similar: --> Like lists, tuples are *ordered* collections of objects --> Like lists, tuples can embed any kind of object --> Like lists, tuples are accessed by offset and, therefore, support offset-based access operations such as indexing and slicing. If you wanted to use an object that consists of the first 5 prime numbers, you can use either a list or a tuple: a = [2, 3, 5, 7, 11] b = (2,3,5,7,11) Thus, print a[2] print b[2] will give you the same result, namely the number 5 But suppose you want to change a and b to add the next prime number. The following works perfectly for a, which is a list and is *mutable* a.append(13) a has now mutated (i.e. changed) to the object: [2,3,5,7,11,13] Try to change or mutate a tuple and you will get an error message. In fact, you can't perform any operations on tuples which change the object once defined. Why might you use tuples? When you have a set of objects that you are fixed and you don't expect to change throughout the life of your program. For example, if you want to store the letters in the English alphabet. ('a', 'b',....)

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    given all that, lists have lots of methods and sometimes it makes things easier to turn you tuple into a list then do stuff to it then turn it back into a tuple

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.