1. What is a tuple in Python?
2. How are elements of a tuple accessed?
3. What will be the output of the following code? Python Code: tuple1 = (2, 4, 6, 8, 10) print(tuple1[3])
4. What is the result of trying to change an element in a tuple?
5. How can you create a tuple with a single element?
6. What is the correct way to create an empty tuple?
7. Which method is used to concatenate two tuples?
8. What will be the output of the following code? Python Code: tuple1 = (1, 3, 5) tuple2 = (2, 4, 6) print(tuple1 + tuple2)
9. What operator is used to repeat elements of a tuple?
10. How can you check if an element is present in a tuple?
11. What will be the output of the following code? Python Code: tuple1 = ('Hello',) * 3 print(tuple1)
12. Which function returns the length of a tuple?
13. Which method returns the number of times an element appears in a tuple?
14. How do you create a tuple from a list?
15. What is the result of the following operation? Python Code: tuple1 = (1, 2, 3) tuple2 = (4, 5, 6) result = tuple1 * 2 + tuple2 print(result)
16. What will be the output of the following slicing operation? Python Code: tuple1 = (10, 20, 30, 40, 50, 60, 70, 80) print(tuple1[2:5])
17. Which function returns a tuple?
18. What will be the output of the following code? Python Code: tuple1 = (1, 2, 3, 4, 5) print(tuple1[-1])
19. How can you iterate through a tuple?
20. What is the purpose of the `index()` method in tuples?
21. Which method returns the index of the first occurrence of an element in a tuple?
22. How can you reverse a tuple?
23. What is the result of the following slicing operation? Python Code: tuple1 = (1, 2, 3, 4, 5, 6, 7, 8) print(tuple1[::2])
24. Which operator is used to check if an element is not present in a tuple?
25. What will be the output of the following code? Python Code: tuple1 = ('Red', 'Green', 'Blue') print('Yellow' in tuple1)
26. How do you create a tuple with the numbers 1 to 5?
27. What is the output of the following code? Python Code: tuple1 = (1, 2, (3, 4), 5) print(tuple1[2])
28. What is the correct way to concatenate two tuples?
29. What will be the output of the following code? Python Code: tuple1 = ('a', 'b', 'c', 'd') print(tuple1[:2])
30. What is the output of the following code? Python Code: tuple1 = ('x', 'y', 'z') tuple2 = ('a', 'b') tuple3 = tuple1 + tuple2 print(len(tuple3))
31. What is a dictionary in Python?
32. How are elements in a dictionary accessed?
33. Which of the following is the correct syntax for creating a dictionary?
34. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} print(dict1['b'])
35. How can you add an element to a dictionary?
36. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} dict1['d'] = 4 print(dict1)
37. How can you remove an element from a dictionary?
38. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} del dict1['b'] print(dict1)
39. How can you access all keys in a dictionary?
40. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} keys = list(dict1.keys()) print(keys)
41. How can you access all values in a dictionary?
42. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} values = list(dict1.values()) print(values)
43. How can you access all key-value pairs in a dictionary?
44. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} items = list(dict1.items()) print(items)
45. How can you check if a key exists in a dictionary?
46. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2, 'c': 3} print('b' in dict1)
47. How can you update a dictionary with another dictionary?
48. What will be the output of the following code? Python Code: dict1 = {'a': 1, 'b': 2} dict2 = {'b': 3, 'c': 4} dict1.update(dict2) print(dict1)
-
A)

No comments: