Learn how to create a tuple in Python. A tuple is an immutable data type that contains several items similar to a list. Items in a tuple can be of any data type.
Instructor: 0:01 Let's start by entering to the Python REPL using the Python 3 command. We can create our tuple by first assigning it the variable name, myTuple.
0:11 Tuples are defined using parentheses. Since items within tuples do not have to be the same data type, I'm going to fill this tuple with information about myself, starting with my first and last name, which are both strings.
0:22 I'm also going to include a small list of my favorite numbers, 8, 12, and 24, and I'm going to end it with the current year, 2020, which is an integer. We can type myTuple into the REPL for the values inside to be returned back to us. We can use the type() method to check the type of myTuple and as it should, it returns back to us class tuple.
You must be a Pro Member to view code
Access all courses and lessons, track your progress, gain confidence and expertise.