Python Tuples
Python Tutorial » Python Tuples
Tuples are sequences, just like lists. Tuples are used to store multiple items in a single variable.
The differences between tuples and lists are, tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
Example: Create Python List:
Output:
('John', 'Ann', 'Chris', 'Tom')
my_tuple = ("John", "Ann", "Chris", "Tom")
print(my_tuple)
print(my_tuple)
Output:
('John', 'Ann', 'Chris', 'Tom')
Python Tuplets Allow Duplicates - examples
Example:
('John', 'Ann', 'Chris', 'Tom', 'John', 'Tom')
my_tuple = ("John", "Ann", "Chris", "Tom", "John", "Tom")
print(my_tuple)
Output: print(my_tuple)
('John', 'Ann', 'Chris', 'Tom', 'John', 'Tom')
Tuple Length
Example:
6
my_tuple = ("John", "Ann", "Chris", "Tom", "John", "Tom")
print(len(my_tuple))
Output:print(len(my_tuple))
6
Tuple Items - Data Types
Elements can be of any data type.
Example: elements can be any data type:
('John', 'Ann', 'Chris', 'Tom', 'John', 'Tom')
(9, 22, 31, 12, 87, 3)
(True, False, False)
my_tuple1 = ("John", "Ann", "Chris", "Tom", "John", "Tom")
my_tuple2 = (9, 22, 31, 12, 87, 3)
my_tuple3 = (True, False, False)
print(my_tuple1)
print(my_tuple2)
print(my_tuple3)
Output:my_tuple2 = (9, 22, 31, 12, 87, 3)
my_tuple3 = (True, False, False)
print(my_tuple1)
print(my_tuple2)
print(my_tuple3)
('John', 'Ann', 'Chris', 'Tom', 'John', 'Tom')
(9, 22, 31, 12, 87, 3)
(True, False, False)
python tuple to list, to string, methods, vs list, append, get first, unpacking, first element, to dict, add element
Python Tuples - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.