1. Which of the following is a valid way to create a list in Python?
2. Lists in Python are:
3. What will be the output of the following code? Python Code: list1 = [2, 4, 6, 8, 10, 12] print(list1[3])
4. How are elements of a list separated?
5. Which data types can a list contain?
6. What does the `+` operator do when applied to two lists?
7. What will be the output of the following code? Python Code: list1 = [1, 2, 3] list2 = [4, 5, 6] print(list1 + list2)
8. Which operator is used for list repetition?
9. What will be the output of the following code? Python Code: list1 = ['Hello'] print(list1 * 3)
10. Which of the following checks if an element is in a list?
11. What will be the output of the following code? Python Code: list1 = ['Red', 'Green', 'Blue', 'Yellow'] print(list1[1:3])
12. How do you access the last element of a list?
13. What does the slicing operation list1[2:5] return? Python Code: list1 = ['Red', 'Green', 'Blue', 'Yellow', 'Black']
14. What will be the output of the following code? Python Code: list1 = ['Red', 'Green', 'Blue', 'Yellow'] print(list1[::2])
15. What will be the output of the following code? Python Code: list1 = ['Red', 'Green', 'Blue', 'Yellow'] print(list1[::-1])
16. What does the `append()` method do?
17. What will be the output of the following code? Python Code: list1 = [1, 2, 3] list1.append(4) print(list1)
18. What does the `extend()` method do?
19. What will be the output of the following code? Python Code: list1 = [1, 2, 3] list2 = [4, 5] list1.extend(list2) print(list1)
20. What does the `insert()` method do?
21. Which loop is used to traverse through a list in Python?
22. What will be the output of the following code? Python Code: list1 = ['Red', 'Green', 'Blue'] for item in list1: print(item)
23. How can you access each element of a list using its index?
24. What will be the output of the following code? Python Code: list1 = ['Red', 'Green', 'Blue'] for i in range(len(list1)): print(list1[i])
25. How does a while loop traverse through a list?
26. What does the `remove()` method do?
27. What will be the output of the following code? Python Code: list1 = [1, 2, 3, 4, 3] list1.remove(3) print(list1)
28. What does the `pop()` method do?
29. What will be the output of the following code? Python Code: list1 = [1, 2, 3, 4] print(list1.pop())
30. What does the `clear()` method do?
31. What does the `len()` function return?
32. What does the `sum()` function return when applied to a list of numbers?
33. How do you find the maximum value in a list?
34. What will be the output of the following code? Python Code: list1 = [1, 2, 3, 4] print(max(list1))
35. How do you find the minimum value in a list?
36. What will be the output of the following code? Python Code: list1 = [1, 2, 3, 4] print(min(list1))
37. How do you sort a list in ascending order?
38. What will be the output of the following code? Python Code: list1 = [4, 3, 2, 1] list1.sort() print(list1)
39. How do you sort a list in descending order?
40. What will be the output of the following code? Python Code: list1 = [1, 2, 3, 4] list1.sort(reverse=True) print(list1)
41. How can you create a 2D list in Python?
42. What will be the output of the following code? Python Code: list1 = [[1, 2], [3, 4], [5, 6]] print(list1[1][1])
43. How do you access the first element of the second list in a nested list?
44. What will be the output of the following code? Python Code: list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(list1[2])
45. How do you flatten a 2D list using list comprehension?

No comments: