Understanding Tuples in Python with Examples.
Tuple in Python – Definition, Examples, and Operations In Python, a tuple is one of the built-in data types used to store a collection of items. Tuples are similar to lists, but there is one key difference : tuples are immutable , which means their values cannot be changed after creation. What is a Tuple? A tuple is an ordered collection of elements enclosed in parentheses ( ) and separated by commas. Syntax tuple_name = (item1, item2, item3) Example numbers = ( 10 , 20 , 30 , 40 ) print (numbers) Output: ( 10 , 20 , 30 , 40 ) Characteristics of Tuples Ordered (items have a fixed position) Immutable (cannot be modified) Allows duplicate values Can store different data types Faster than lists (performance benefit) Tuple with Different Data Types student = ( "Rahul" , 21 , 85.5 , True ) print (student) Accessing Tuple Elements You can access tuple elements using indexing . colors = ( "red" , "green" , "blue...