Posts

Showing posts with the label python tuple

Python Tuples Explained for Beginners (With Simple Examples)

Python Tuples Explained for Beginners (With Simple Examples) Python Tuples Explained for Beginners (With Simple Examples) Introduction In the previous post, we learned about Python Lists . Now let’s learn another important data structure in Python called Tuple . Tuples are very similar to lists, but with one major difference — they cannot be changed . --- What is a Tuple? A tuple is a collection of items that is: Ordered Immutable (cannot be modified) Allows duplicate values Once a tuple is created, you cannot add, remove, or change its elements. --- How to Create a Tuple Tuples are created using round brackets ( ) . numbers = (10, 20, 30) print(numbers) --- Tuple with Different Data Types A tuple can store multiple data types together. data = ("Ayush", 22, True, 75.5) print(data) --- Accessing Tuple Elements You can access tuple elements using index numbers . colors = ("red", "green", ...