Posts

Showing posts from September, 2022

Python tuples

Tuples are built-in data type in Python used to store multiple data elements in a single variable. They are similar to lists in terms of indexing, nesting, and repetition, but the main difference is that tuples are immutable , meaning they cannot be modified once created. In Python, tuples are written with round brackets. Let's explore the various aspects of tuples and how to work with them efficiently. Creating and Accessing Values in Tuples To create a tuple, simply enclose the elements within round brackets. Here's an example: python var = ( "programming" , "for" , "students" ) print (var) Output: output ( 'programming' , 'for' , 'students' ) You can access the values in a tuple using positive or negative indexing. Positive indexing starts from 0, while negative indexing starts from -1 (representing the last element). Here's how to access tuple values using indexing: python var = ( "programming" , "fo