Python Create a Tuple with Example

A tuple is a collection of immutable and ordered Python objects. It can hold elements of any arbitrary data type (integer, string, float, list, etc.). The difference between the two is that we cannot change the elements of a tuple whereas we can change the elements of a list.

A tuple can be created by putting different comma-separated values between parentheses(). You can also create a tuple without putting items in parentheses too.

# empty tuple
empty_tuple = ()

# without parentheses
wp_tuple = ('python', 'shouts')

# without parentheses
wop_tuple = 'python', 'shouts'

# different datatypes
ddt_tuple = (1.5, "Hi", 3, -10)

# nested
nested_tuple = ("Hello", [1, 2, 3], (1, 5, 7))


('python', 'shouts')
('python', 'shouts')
(1.5, 'Hi', 3, -10)
('Hello', [1, 2, 3], (1, 5, 7))

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.