Python 3 Programming Tutorial – Lists and Tuples

In this programming tutorial, we cover Python lists and tuples.

Both data structures contain data, but are slightly different. Python lists are mutable, meaning they can be changed and manipulated. Tuples are immutable, meaning they cannot be changed. This is what sets them apart and why you would use a specific one. Lists are usually more popular, since people want to be able to change them, but tuples are also useful when you do not want or need to change the data.

It should also be noted that Tuples are faster to process and iterate through, so this gives them a bonus, again, if you are not needing to manipulate them.

Sample code for this basics series:

Python 3 Programming tutorial Playlist:

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6


22 thoughts on “Python 3 Programming Tutorial – Lists and Tuples”

  1. Hi Harrison. After watching your tutorial on Flask I would like to put what I've learned to work. However, I don't currently have an idea in mind. Well, I have one but not sure it would be easy for a newbie like me to build (some sort of multi-sided platform). As a newbie, should I perhaps focus more on Django or stick with Flask? What would you recommend me to do in order to get the ball rolling regardless of the framework that I end up choosing? Also, I don't know much about database and I'm about to start leaning about it. Would you recommend focusing on SQL, NoSQL, SQL Alchemy? Thanks Harrison.

  2. It would seem the main purpose of a tuple is protecting its data integrity throughout the execution of the script. (January, February, March, …)

  3. Tuples come from more functional languages and are for example used as arguments or return values without the need to create a full class/object (should there even be objects).And usually tuples are collections that have different types of items ("heterogeneous") whereas lists are composed of items of the same type ("homogeneous"). There are even programming languages that require lists to always have the same item type. Python doesn't seem to.A line of a CSV file read in as a tuple makes sense or as we have seen sockets use (host, port) pairs. Or like using a tuple for a vector (x, y) because x has no meaning without y and vice-versa, there is an "intimate" relationship (same argument could be made for host, port). F# has guidance for this e. g. regarding function parameters.

  4. I am much more proficient in C++ but am taking a crack at Python and I am liking it a lot.
    I know this video is old but I have a question to ask you.
    I have a little practice program I am trying to do. I am trying to create a function that adds 'and' to the -1 spot of a list any list that is passed to it.
    I know what I have to do but I do not know how to do it.

    With the insert I need to insert 'and' at the element -1 so something like modList.insert(-1,x)
    Where the x is though I am trying to ADD to whatever is in the -1 spot and add 'and' before it but without the ' '.

    This is what I have so far:

    def modList(someList):
    someList.insert(-1, 'and')

    spam = ['Dog','Cat','Bat','Mouse']

    OUTPUT: ['Dog', 'Cat', 'Bat', 'and', 'Mouse']
    Desired OUTPUT: ['Dog, Cat, Bat, and Mouse']

    Any help is much appreciated…

  5. I love your videos, man. The addition of the video box was really nice. This is 2014 so I'm sure you've made even more improvements since then. I'm developing a game for fun and you're helping me further my understanding of the Python language. What playlist would you recommend I begin watching after I learn more of the basics? I saw one using PyGame, but I'll probably end up watching a bunch of others just to make sure I know the core language in-and-out.

  6. you know brother 🙂
    I started watching your videos and I cannot stop 😀
    I really appreciate your efforts and I really thank you.
    In my religion we say something better than thanking which is "Jazakom Allah Khayran"
    So I do both I thank you and I say "Jazakom Allah Khayran = I ask Allah to give you the best always ….Ameen"
    All my respect and regards

  7. What are the direct 2 methods to construct a tuple that has only a single item? How many ways are there to construct a list with a single item?

  8. First of all, I love your videos!

    The thing is, I can't understand the mutableness of lists and tuples. You said lists are mutable and tuples aren't. What exactly does 'changing lists or tuples' means?

  9. Will it not be x = exampleFunc()? because in the case of x, y = exampleFunc(), it will declare simple integer variables to hold the returned values. right? I ran to confirm it and it is working the way I am suggesting.

Leave a Reply