0% found this document useful (0 votes)
2 views6 pages

Python List Adding

Uploaded by

swatithakur20938
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python List Adding

Uploaded by

swatithakur20938
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python list/adding element in a list/removing elements

from the list/list accessing


1. In ........... checks the elements of a list, one at a time, without skipping any element.

Answer: Linear search

Explanation:
Linear search checks elements one by one from start to end.

Binary search works only on sorted lists.

Hash search uses hash tables.

2.

list1=[3,2,5,7,3,6]

[Link](3)

print(list1)

Answer: [3,2,5,3,6]
(Your options seem incorrect, but this is the correct output.)

Explanation:
pop(3) removes element at index 3.

Indexes:

0→3

1→2

2→5

3→7

So 7 is removed.

Final list:

[3,2,5,3,6]

3. The process of placing or rearranging elements into order is known as

Answer: Sorting
Explanation:
Sorting arranges data in ascending or descending order.

4. Correct syntax for slicing operation

Answer: print(list1[:2])

Explanation:
[:2] returns first two elements.

Example:

[4,2]

[-:2] is invalid syntax.

5. To remove the string "Know Program" from list

Answer: [Link]("Know Program")

Explanation:
remove() deletes a specific value from list.

6. To add a new element to a list

Answer: [Link](5)

Explanation:
append() adds element at end of list.

7. list1[-1]

list1=[2,33,222,14,25]

Answer: 25

Explanation:
Negative indexing starts from end.

-1 → last element

8. Operator used to separate list items

Answer: , (Comma)
Explanation:
List items are separated using commas.

Example:

[1,2,3]

9. Method used to delete element in list

Answer: remove()

Explanation:
remove() deletes value from list.

10. sum(list1)

list1=[1,5,9]

Answer: 15

Explanation:

1+5+9 = 15

11. list1 * 2

list1=[1,3,2]

Answer: [1,3,2,1,3,2]

Explanation:
*2 repeats the list twice.

12. count() method is used for

Answer: Count item occurrence

Explanation:
count() counts how many times an item appears.

Example:

[1,1,2].count(1)

Output:

2
13. Last index using negative indexing

Answer: -1

Explanation:
-1 refers to last element.

14. Python list can store

Answer: All of these

Explanation:
Lists can contain:

• numbers,

• strings,

• mixed data,

• nested lists.

15. list1[:-1]

list1=[2,33,222,14,25]

Answer: [2,33,222,14]

Explanation:
[:-1] means all elements except last.

16. min(list1)

list1=[3,5,25,1,3]

Answer: 1

Explanation:
min() returns smallest element.

17. Function used to convert list items into string

Answer: join()

Explanation:
join() combines list strings into one string.

Example:
" ".join(["a","b"])

Output:

"a b"

18. List can contain values of these types

Answer: All of these

Explanation:
Lists support mixed data types.

19. Append method adds value at

Answer: Last

Explanation:
append() always adds at end.

20. max(list1)

list1=[5,50,1025,100]

Answer: 1025

Explanation:
max() returns largest element.

21. Function used to count total elements in list

Answer: len()

Explanation:
len() gives total number of elements.

22. Function used to delete all list items

Answer: clear()

Explanation:
clear() empties the entire list.
23. Insert 3 at second position

Answer: [Link](1,3)

Explanation:
Indexing starts from 0.

Second position → index 1.

24. Index of first element in python list

Answer: 0

Explanation:
Python uses zero-based indexing.

25. Method used to fetch and remove last items one after another

Answer: pop()

Explanation:
pop() removes and returns the last element by default.

You might also like