Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
46.
How do you convert a tuple to a string?
str(tuple)
tuple.toString()
tuple.join('')
string(tuple)
Answer: Option
Explanation:
The str() function is used to convert a tuple to a string.

47.
What is the result of the expression tuple((1, 2, 3)) * 3?
(1, 2, 3, 1, 2, 3, 1, 2, 3)
((1, 2, 3), (1, 2, 3), (1, 2, 3))
[1, 2, 3, 1, 2, 3, 1, 2, 3]
(1, 2, 3, (1, 2, 3), (1, 2, 3))
Answer: Option
Explanation:
The '*' operator is used to repeat the elements of the tuple.

48.
What does the tuple() function do when given a list as an argument?
Creates a tuple containing the entire list as a single element.
Converts the list into a tuple.
Raises a TypeError since lists and tuples are incompatible.
Appends the list to an existing tuple.
Answer: Option
Explanation:
The tuple() function can be used to convert a list into a tuple.

49.
What is the result of the expression len(('apple',))?
5
1
('apple',)
Raises a TypeError
Answer: Option
Explanation:
The len() function returns the number of elements in the tuple, which is 1 in this case.

50.
How can you check if two tuples are equal?
tuple1.equals(tuple2)
tuple1 == tuple2
tuple1.compare(tuple2)
tuple1 is tuple2
Answer: Option
Explanation:
The '==' operator is used to check if two tuples are equal.