📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 138question

LISTS, TUPLES, SETS AND DICTIONARY · Part 14

Chapter 3: 4 · COMPUTER SCIENCE

statement in the above code prints the elements. Then, the del statement deletes the entire tuple. When you try to print the deleted tuple, Python shows the error. .

. Tuple Assignment Tuple assignment is a powerful feature in Python. It allows a tuple variable on the left of the assignment operator to be assigned to the values on the right side of the assignment 12th Computer Chapter - - operator. Each value is assigned to its respective variable.

a = b c >>> (a, b, c) = ( , , ) >>> print(a,b,c) # expression are evaluated before assignment >>> (x, y, z, p) = ( ** , / + , % , > ) >>> print(x,y,z,p) .666666666666667 False Example Note that, when you assign values to a tuple, ensure that the number of values on both sides of the assignment operator are same; otherwise, an error is generated by Python. . . Returning multiple values in Tuples A function can return only one value at a time, but Python returns more than one value from a function.

Python groups multiple values and returns them together. def (n): a = max(n) b = min(n) return(a, b) Num = ( , , , , , , ) ( , ) = (Num) print("Maximum value = ", ) print("Minimum value = ", ) Output: Maximum value = Minimum value = Example : Program to return the maximum as well as minimum values in a list 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary . . Nested Tuples In Python, a tuple can be defined inside another tuple; called Nested tuple.

In a nested tuple, each tuple is considered as an element. The for loop will be useful to access all the elements in a nested tuple. Toppers = (("Vinodini", "XII-F", . ), ("Soundarya", "XII-H", .

), ("Tharani", "XII-F", . ), ("Saisri", "XII-G", . )) for i in Toppers: print(i) Output: ('Vinodini', 'XII-F', . ) ('Soundarya', 'XII-H', .

) ('Tharani', 'XII-F', . ) ('Saisri', 'XII-G', . ) Example Some of the functions used in List can be applicable even for tuples. Note

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →