Python Arrays Questions and Answers
Python Programming - Arrays Questions with Answers explain how to store and access multiple values efficiently. These Python Arrays Questions are essential for TCS, SSC, and Infosys exams covering fundamental data structure concepts
Python Arrays
Showing 10 of
25 questions
11. How do you get the number of elements in a Python list?
- len(list)
- list.size()
- list.length()
- list.count()
12. What is list comprehension in Python?
- A concise way to create lists
- A method to comprehend list structure
- A way to read lists from files
- A technique to compress lists
13. Which method removes all elements from a list?
- clear()
- empty()
- delete_all()
- remove_all()
14. What is the output of [x**2 for x in range(5) if x % 2 == 0]?
- [0, 4, 16]
- [0, 1, 4, 9, 16]
- [0, 4]
- [1, 9]
15. How do you sort a list in descending order?
- sort(reverse=True)
- sort(descending=True)
- sort(order="desc")
- reverse_sort()
16. What is the difference between sort() and sorted()?
- sort() modifies in-place, sorted() returns new list
- sort() is faster than sorted()
- sorted() works only for numbers
- There is no difference
17. How do you check if an element exists in a list?
- element in list
- list.contains(element)
- list.exists(element)
- list.find(element) != -1
18. What does the slice notation list[1:4] return?
- Elements from index 1 to 3
- Elements from index 1 to 4
- First 4 elements
- Elements from index 0 to 3
19. How do you create a list with 5 zeros?
- [0] * 5
- list(5, 0)
- zeros(5)
- list.zeros(5)