Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Python Basics: Lists and Tuples (Summary)

You now have a solid understanding of Python lists and tuples. Throughout the course, you’ve learned about their structure, functionality, and differences. You’ve also gained practical skills in defining and manipulating these data structures within your Python code.

In this video course, you’ve learned:

  • What lists and tuples are and how they’re structured
  • How lists and tuples differ, including their mutability and immutability
  • How you can define, manipulate, and access elements within lists and tuples
  • How lists and tuples compare to other data structures in Python

With this knowledge, you can organize and manage collections of data with ease. Now that you have a solid grasp of lists and tuples, continue practicing and exploring their capabilities. This will further enhance your programming skills and enable you to tackle more complex tasks in Python.

This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. You can also check out the other Python Basics courses.

Download

Sample Code (.zip)

20.1 KB
Download

Course Slides (.pdf)

8.9 MB

00:00 That’s a wrap. You’ve made it to the end of this Python Basics course about tuples and lists, and along the way you’ve covered a lot of topics.

00:09 First, you learned about tuples as immutable sequences, and you learned how you can think of tuples as rows in a spreadsheet or records in a database, how you can create tuples, compare tuples and strings to get an idea of how they’re similar and how they’re different.

00:25 You learned how you can unpack tuples and assign multiple variables in one go using this trick. You learned how you can check for the existence of values using the in keyword and also how you can return multiple values from a function or really just return a tuple that contains multiple values from a function.

00:46 Next, we moved on to lists, which are mutable sequences, and you compared how tuples and lists are similar and dissimilar. You started off by creating lists using the square brackets and the list() function, and then also how you can work with them similarly to how you can work with tuples, but of course there’s the big difference that lists are mutable, so you learned about what that means and how you can change elements in a list, add and remove elements using slice notation or also the dedicated list methods.

01:18 And then you moved on to working with lists of numbers, so how some built-in Python functions such as sum() can take a collection and make your life a little easier.

01:27 You learned how you can create list comprehensions and that they are just a shorthand for writing a for loop. You’ve learned how you can nest and copy lists and the trickiness about copying lists that is rooted in their mutability.

01:42 And then finally, you also learned how you can sort lists.

01:46 Now, like I mentioned, this is quite a lot of content that you’ve covered here, but both lists and tuples are important data structures in Python that you’ll work with a lot.

01:58 If you want to continue diving into these two data structures, then we have more resources for you. There’s a tutorial about lists and tuples in Python that also has an associated video course.

02:09 Then there’s two deep-dive articles, one dedicated to the list data type and one dedicated to the tuple data type. Check those out. You can learn a lot more about each of those data structures in Python when you read through these articles.

02:25 Finally, there are also some other related topics that I want to mention. If you want a dedicated article about Python’s .append(), then we have that as well as an associated video course, and if you want to learn how you can reverse Python lists in a different way than you’ve seen in this course, then there’s a dedicated article for that.

02:44 And also a commonly talked about topic about how you can flatten a list of lists, we have a specific article for that as well.

02:52 So as you can see, there’s a lot of resources on the site and there’s even more if you search for tuples and lists on the site.

03:00 All right, thank you for joining for this Python Basics course about tuples and lists. I hope you enjoyed it and that you have a better understanding of what these important data structures are and how you can work with them.

KimP on Feb. 2, 2024

Don’t see how to increment Row number in exercise:

for item in data:
    row = 0
    print(f"Row {row + 1} sum: {sum(item)}")

Martin Breuss RP Team on Feb. 2, 2024

@KimP try to debug your code by printing for each loop what the value of row is.

You probably want to move one of the lines in your code outside of the for loop.

KimP on Feb. 3, 2024

Fixed it in the end by using the index() method:

for item in data: print(f”Row {data.index(item) + 1} sum: {sum(item)}”)

Become a Member to join the conversation.