From the course: Programming Foundations: Real-World Examples
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Tuples - Python Tutorial
From the course: Programming Foundations: Real-World Examples
Tuples
- Lists can easily be changed by adding, removing, or modifying objects. There is another data type called the tuple which is similar to a list except for one key difference. A tuple is immutable which means it cannot be changed. Just like a list, a tuple contains a sequence of objects in order but once you've created a tuple, you can't change anything about it. So why would you want to use this tuple thing which is basically just a more restrictive version of a list? The short answer is simplicity. If I need to store or pass some nugget of information that's never going to change, then a tuple is a handy container to do that. For example, when I was driving to the store earlier, I used the GPS function on my cellphone to help me navigate. When I use the GPS to find out where I am, it returns the answer as two values, a latitude and a longitude. Those two values always go together in that order so it makes sense for the GPS function to return them to me as a tuple. There's no reason I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.