From the course: Programming Foundations: Data Structures (2023)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Tuples in Python - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
Tuples in Python
- [Instructor] Another array-like data structure in Python is a tuple. A tuple is similar to a list, but it's immutable. This is helpful for storing a collection of values that should not be changed. For example, coordinates or RGB values. To create a tuple in Python, we use parentheses and separate each value with a comma. We'll call this a point. Now that it's been created, we cannot modify it. To access each value in a tuple, we use indexing just like a list. We'll say X is at index zero, and Y is at index 1. In addition to storing values, tuples can also be used to return multiple values from a function. Let's create a function that returns the area and perimeter of a square. We'll call it calculate_square_properties and it'll take in a side length. With this length, we can compute the area and the perimeter. To return them both, we can use the tuple. We don't need to include the parentheses if we don't want to but…
Contents
-
-
-
-
What is an array?3m 31s
-
(Locked)
Create a list in Python2m 27s
-
(Locked)
Retrieve data from a list in Python4m 26s
-
(Locked)
Mutate a list in Python2m 57s
-
(Locked)
Multidimensional lists7m 15s
-
(Locked)
Tuples in Python2m 45s
-
(Locked)
Search array-like structures4m 47s
-
(Locked)
Sort array-like structures5m 1s
-
(Locked)
Challenge: Find the second smallest item1m 35s
-
(Locked)
Solution: Find the second smallest item4m 26s
-
(Locked)
When to use array-like structures1m 15s
-
-
-
-
-
-
-