Tuple

Topic

Tuple

Topic Progress:

A tuple in python is mostly the same as a list where we can store a collection of items. The list below describes the different properties of a tuple. Most of the time you will be wanting to use a list instead of a tuple

  • A collection of items stored together in a single variable
  • Each item is kept in a specific order
  • Items within the list CANNOT be changed
  • duplicate items can be stored in the list

To create a new tuple we first need a variable and then to set it to the items inside of brackets () instead of square brackets as shown below.

exampleList = ("hello","welcome","to","codecamp")

Aside from creating the tuple and not being able to edit the tuple it functions exactly the same as a list as shown in the repl.it code below.

Printing the whole tuple

Printing the first item

Printing the whole tuple using a for loop

@

Not recently active