Exploring Python's tuple Data Type With Examples (Overview)
In Python, a tuple
is a built-in data type that allows you to create immutable sequences of values. The values or items in a tuple can be of any type. This makes tuples pretty useful in those situations where you need to store heterogeneous data, like that in a database record, for example.
Through this tutorial, you’ll dive deep into Python tuples and get a solid understanding of their key features and use cases. This knowledge will allow you to write more efficient and reliable code by taking advantage of tuples.
In this video course, you’ll learn how to:
- Create tuples in Python
- Access the items in an existing tuple
- Unpack, return, copy, and concatenate tuples
- Reverse, sort, and traverse existing tuples
- Explore other features and common gotchas of tuples
00:00 Welcome to Exploring Python’s tuple Data Type With Examples. My name’s Joseph, and I’ll be your instructor for this video course. This course is a deep dive into one of Python’s most important, but often underappreciated data types, the tuple.
00:14 If you’ve spent any significant time writing Python code, you’re probably familiar with tuples. You might know that they’re like lists, but with parentheses, right?
00:22 And that they’re also immutable. So while those two things are true, you’ll soon see that there’s a lot more to tuples. In fact, good use of tuples is key to writing clean, performant, and idiomatic Python code.
00:35 So in this course, you’ll learn how to
00:38 create tuples in Python, access the elements in an existing tuple, use tuple packing and tuple unpacking, apply common operators to tuples, such as the addition, and multiplication operators, reap the benefits while avoiding the pitfalls of tuple immutability, and finally, improve the efficiency and readability of your code using tuples.
00:59 Unfortunately, the one thing you won’t learn in this course is whether it’s pronounced “toople” or “tupple”. I’m sorry, but that’s beyond me. I prefer the sound of tuple, so that’s what I’m going with.
01:12 The code examples you’ll be seeing in this course, we’ll be using bpython, a custom Python REPL. However, none of the code will depend on bpython, and you’re free to follow along using the built-in Python REPL.
01:25 So if you’re ready to dive in, meet me in the next lesson where we’ll start by tackling that fundamental question. What exactly is a tuple?
Become a Member to join the conversation.