Short Answer Type Questions (2/3 Marks each)

Computer Science - Class 11
Chapter 10 Class 11 - Tuples and Dictionaries

## ``` t=tuple()  t = t + (‘Python’,)  print t  print len(t)  t1= (10,20,30)  print len(t1)  ```

The output of the code is:

('Python',)

1

3

Explanation:

• The code creates an empty tuple by using a pair of empty parentheses and assigns it to a variable t.
• The code then creates another tuple with one element ‘Python’ and assigns it to a variable t. This is done by using a comma after the element to indicate that it is not just a parenthesis around an expression. The code then uses the + operator to concatenate (join) the two tuples and assign the result back to t.
• The code then prints the value of t using the print() function. The print() function displays the output to the standard output device (usually the screen). The output of this line is (‘Python’,), which is a tuple with one element.
• The code then prints the length of t using the len() function and the print() function. The len() function returns the number of elements in a sequence (such as a tuple). The output of this line is 1, which is the number of elements in t.
• The code then creates another tuple with three elements 10, 20, and 30 and assigns it to a variable t1. This is done by using parentheses and commas to separate the elements.
• The code then prints the length of t1 using the len() function and the print() function. The output of this line is 3, which is the number of elements in t1.

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class 