List in python: 17 flashcards

All 17 flashcards from this kit, free and with no sign-up.

1. How do you create an empty list in Python?

Show the answer

`[]` or `list()`

2. What is the index of the first element in a Python list?

Show the answer

0

3. Given `my_list = [10, 20, 30]`, what does `my_list[-1]` return?

Show the answer

30

4. Write the syntax to access the third element of a list named `data`.

Show the answer

`data[2]`

5. What does `len([5, 10, 15])` return?

Show the answer

3

6. How do you change the second element of list `nums = [1, 2, 3]` to 99?

Show the answer

`nums[1] = 99`

7. What is the result of `[1, 2] + [3, 4]`?

Show the answer

`[1, 2, 3, 4]`

8. What does `[0] * 4` produce?

Show the answer

`[0, 0, 0, 0]`

9. Write a list comprehension that creates a list of squares for numbers 0 to 4.

Show the answer

`[x**2 for x in range(5)]`

10. What does `[1, 2, 3, 4, 5][1:4]` return?

Show the answer

`[2, 3, 4]`

11. How do you check if `5` is in list `nums`?

Show the answer

`5 in nums`

12. What is the output of `[1, 2, 3].index(2)`?

Show the answer

1

13. What does `[3, 1, 2].sort()` do?

Show the answer

Sorts the list in place to `[1, 2, 3]`

14. What is the difference between `list.append(x)` and `list.extend([x])`?

Show the answer

`append` adds `x` as a single element; `extend` adds each element of the iterable separately.

15. What does `[10, 20, 30].pop(1)` return and what is left in the list?

Show the answer

Returns `20`; list becomes `[10, 30]`

16. How do you remove the first occurrence of `3` from `[1, 3, 2, 3]`?

Show the answer

`[1, 3, 2, 3].remove(3)`

17. What is the result of `list('abc')`?

Show the answer

`['a', 'b', 'c']`

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages