Learn with Yasir

Share Your Feedback

Python Lists Fill in the Blanks – Practice Exercises for Beginners

Sharpen your Python list skills with fill-in-the-blank exercises. Practice indexing, slicing, list methods, and more to reinforce your understanding of core list operations in Python.

Topic: lists


🔍 Fill in the Blanks

🟢 Beginner

  1. To create a list with elements 1, 2, and 3, we write: ______ = [1, 2, 3]
  2. Answer

    any_valid_variable_name

    Lists are created using square brackets, and can be assigned to any valid variable name.


  3. To access the last element of list `my_list`, we use: my_list[______]
  4. Answer

    -1

    Negative indices count from the end (-1 is last element, -2 is second last, etc.)


  5. To add an element 5 to the end of `my_list`, we use: my_list.______(5)
  6. Answer

    append

    append() adds a single element to the end of the list


🟡 Intermediate

  1. To get every second element from index 1 to 5 in `nums`, we write: nums[______]
  2. Answer

    1:6:2

    The slice start:stop:step gets elements from start to stop-1, stepping by step


  3. To reverse a list `items` in-place, we use: items.______()
  4. Answer

    reverse

    The reverse() method reverses the list elements in their place


  5. To find the index of first occurrence of 'apple' in `fruits`, we use: fruits.______('apple')
  6. Answer

    index

    index() returns the position of the first matching element


🔴 Advanced

  1. To create a shallow copy of `original_list`, we can use: new_list = ______[:]
  2. Answer

    original_list

    Slicing with [:] creates a new copy of the entire list


  3. To remove all elements from `my_list` while keeping the object, we use: my_list.______()
  4. Answer

    clear

    clear() empties the list while maintaining the list object



🧠 Example-Based Fill in the Blanks

  1. colors = ['red', 'green', 'blue']
    print(colors[______])
    

    ✍️ To print 'green' from the list, fill in the blank

    Answer

    1

    List indices start at 0, so 'green' is at position 1

  2. numbers = [1, 2, 3, 4, 5]
    subset = numbers[______]  # Gets [2, 3, 4]
    

    ✍️ Fill in the slice to get elements at indices 1 to 3

    Answer

    1:4

    Slices are start-inclusive and end-exclusive

  3. data = [10, 20, 30]
    data.______(40)
    print(data)  # Outputs [10, 20, 30, 40]
    

    ✍️ Fill in the method call to add 40 to the list

    Answer

    append

    append() adds an element to the end of the list


📚 Related Resources