Python Tuples - 30 Multiple Choice Questions

image
Python Tuples MCQs - 30 Important Questions with Answers (Beginner to Advanced) Python Tuples - 30 Multiple Choice Questions

Python Tuples - 30 Multiple Choice Questions

1. What is the syntax to create a tuple in Python?
A) `tuple{}`
B) `[]`
C) `()`
D) `{}`
Answer: C
2. How do you access the first element of a tuple named `my_tuple`?
A) `my_tuple[0]`
B) `my_tuple(1)`
C) `my_tuple.first()`
D) `my_tuple{1}`
Answer: A
3. Can you modify the elements of a tuple?
A) Yes
B) No
C) Only the first element
D) Only if declared with `list`
Answer: B
4. Which method can you use to find the length of a tuple?
A) `len(tuple)`
B) `count(tuple)`
C) `size(tuple)`
D) `length(tuple)`
Answer: A
5. How do you create a tuple with one element?
A) `(1)`
B) `(1,)`
C) `[1]`
D) `tuple(1)`
Answer: B
6. What does `tuple((1, 2, 3))` return?
A) `(1, 2, 3)`
B) `[1, 2, 3]`
C) `1, 2, 3`
D) `Error`
Answer: A
7. Which of the following is a valid tuple?
A) `(1, 2, 3)`
B) `1, 2, 3`
C) `[1, 2, 3]`
D) `{1, 2, 3}`
Answer: A
8. How do you concatenate two tuples `a` and `b`?
A) `a + b`
B) `a.append(b)`
C) `a.concat(b)`
D) `a.join(b)`
Answer: A
9. What is the output of `(1, 2, 3) * 2`?
A) `(1, 2, 3)`
B) `(1, 2, 3, 1, 2, 3)`
C) `Error`
D) `2, 3, 1`
Answer: B
10. How can you convert a list to a tuple?
A) `tuple(list)`
B) `list(tuple)`
C) `convert(list)`
D) `tuple[]`
Answer: A
11. Which of the following can hold a tuple?
A) List
B) Dictionary
C) Set
D) All of the above
Answer: D
12. Can a tuple contain mixed data types?
A) Yes
B) No
C) Only strings
D) Only numbers
Answer: A
13. What is the result of `((1, 2), (3, 4))`?
A) A tuple of tuples
B) A list
C) A set
D) An integer
Answer: A
14. How do you unpack a tuple?
A) `a, b = (1, 2)`
B) `a = (1, 2)`
C) `unpack((1, 2))`
D) `a.b = (1, 2)`
Answer: A
15. What will be the output of `print((1, 2) + (3, 4))`?
A) `(1, 2, 3, 4)`
B) `(1, 2) (3, 4)`
C) `Error`
D) `1, 2, 3, 4`
Answer: A
16. How do you access the last element of a tuple?
A) `tuple[-1]`
B) `tuple[len(tuple)]`
C) `tuple.last()`
D) `tuple(end)`
Answer: A
17. What is the output of `print((1, 2, 3)[1])`?
A) `1`
B) `2`
C) `3`
D) `Error`
Answer: B
18. How do you check if an element exists in a tuple?
A) `element in tuple`
B) `tuple.has(element)`
C) `tuple.contains(element)`
D) `element.exists(tuple)`
Answer: A
19. Which of the following operations can be performed on tuples?
A) Indexing
B) Slicing
C) Concatenation
D) All of the above
Answer: D
20. What will `print((2, 3, 4).count(3))` return?
A) `0`
B) `1`
C) `2`
D) `Error`
Answer: B
21. Can you nest tuples inside tuples?
A) Yes
B) No
C) Only if they are of the same type
D) Only in Python 3
Answer: A
22. How would you create a tuple with no elements?
A) `()`
B) `[]`
C) `{}`
D) `tuple()`
Answer: A
23. What is the result of `((1, 2),) * 2`?
A) `((1, 2), (1, 2))`
B) `((1, 2, 1, 2))`
C) `Error`
D) `2, 1, 2`
Answer: A
24. Which function can convert a tuple to a list?
A) `list(tuple)`
B) `tuple.list()`
C) `toList(tuple)`
D) `convert(tuple)`
Answer: A
25. What does the `index` method do for a tuple?
A) Returns the first occurrence of an element
B) Modifies the tuple
C) Returns the number of elements
D) Concatenates tuples
Answer: A
26. How can you find the maximum value in a tuple?
A) `max(tuple)`
B) `tuple.max()`
C) `tuple.high()`
D) `maximum(tuple)`
Answer: A
27. What will be the output of `print((1, 2, 3) + (4, 5))`?
A) `(1, 2, 3, 4, 5)`
B) `Error`
C) `1, 2, 3, 4, 5`
D) `(1, 2) (3, 4, 5)`
Answer: A
28. Which operator is used for tuple repetition?
A) `*`
B) `+`
C) `-`
D) `&`
Answer: A
29. What is the result of `print((1, 2, 3)[0:2])`?
A) `(1, 2)`
B) `(1, 2, 3)`
C) `(2, 3)`
D) `Error`
Answer: A
30. How do you iterate through a tuple?
A) `for item in tuple:`
B) `foreach item in tuple:`
C) `tuple.iterate()`
D) `for item in range(tuple):`
Answer: A

© 2024 Python Tuples MCQs

Post a Comment

0 Comments