Think of Tuples as Rows
00:22 So you would pronounce it like in the word quadruple. And another one is tupple, like in the word quintuple. Both of these pronunciations are fine, and both are used throughout the Python community.
00:34 So you can pick. Either you can mix and match, or you can just settle on one of those. It seems like eventually I settled on calling them tooples, even though I remember also talking about them as tupples sometime in the past.
00:46 And I may end up throwing in a tupple here or there during this course just to make sure that everyone’s happy or everyone’s unhappy. I don’t know. Both of these pronunciations are fine and refer to the same thing in Python.
01:00 Now what is that thing in Python? What is a tuple? A tuple is a finite, ordered, immutable sequence of values. That’s a mouthful. It gets worse. Python borrows the name and the notation from mathematics, which means per definition, each element is separated by a comma inside a tuple, and all the elements are surrounded by a single pair of parentheses.
01:28 Okay, so that’s maybe the definition, but it’s not super helpful to really understand what a tuple is. So I want to give you some help in remembering an approximation of how you can think about a tuple in Python.
01:43 It’s very helpful to think about database records in that context, or rows in a spreadsheet. You may have worked with some sort of a spreadsheet application before. You have some sort of idea of what a spreadsheet looks like, and that it consists of multiple columns and multiple rows.
02:09 You could think of a Python tuple as one row in this spreadsheet, or one record in the database, right? So the first row here, you could represent it as a Python tuple as shown at the bottom of this slide.
02:23 So here you would surround the information that is given in the row with parentheses and separate each of the values in each column with a comma. So the first one is the employee ID, which here has the value one.
03:28 It has fixed values—that is, if it’s read-only. And it contains a variety of data types. And the one you saw before, you saw some text and you saw some numbers, and it also usually contains related data.
04:03 Toople? Topple? Then I want you just to think, ah, all right, it’s a read-only database record. And if that approximation gives you some sort of an idea, then I think you’ve got a better grasp on how to think about tuples in Python.
Become a Member to join the conversation.