Create a Tuple in Python

Ceora Ford
InstructorCeora Ford
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

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.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today