Page 275 - CTS - CSA TP - Volume 2
P. 275

COMPUTER SOFTWARE APPLICATION - CITS




           Tuple Slicing









           Tuple Concatenation













           Tuple Unpacking













           Tuples are often used when the order and immutability of elements are important. They are useful in scenarios
           where you want to represent a fixed collection of items that should not be modified during the program execution.
           TASK 1: Basic Tuple
           # Example 1: Creating a basic tuple

           fruits = (‘apple’, ‘banana’, ‘orange’)
           print(fruits)
           # Output: (‘apple’, ‘banana’, ‘orange’)
           Explanation:  In  this  example,  a  tuple  named  fruits  is  created  with  three  elements. Tuples  are  defined  using
           parentheses.
           Output:











           TASK 2: Mixed Tupls

           # Example 2: Tuples with mixed data types
           mixed_tuple = (1, ‘hello’, 3.14, True)
           print(mixed_tuple)
           # Output: (1, ‘hello’, 3.14, True)
           Output:



                                                           260

                              CITS : IT & ITES - Computer Software Application - Exercise 128                                                        CITS : IT & ITES - Computer Software Application - Exercise 128
   270   271   272   273   274   275   276   277   278   279   280