Editor

Lists: What Does This Print

What does this print? · Beginner · about 6 min

Read each short program and type exactly what it prints, with each printed line on its own line. If a program stops with an error, type the error's name, like TypeError.

Example

nums = [4, 5]
nums.insert(0, 3)
print(nums)

prints

[3, 4, 5]
  1. Program 1

    nums = [3, 1, 2]
    nums.append([4, 5])
    print(len(nums))
  2. Program 2

    nums = [3, 1, 2]
    nums.extend([4, 5])
    print(nums)
  3. Program 3

    a = [1, 2, 3]
    b = a
    b.append(4)
    print(a)
  4. Program 4

    a = [1, 2, 3]
    b = a[:]
    b.append(4)
    print(a, b)
  5. Program 5

    nums = [5, 2, 8]
    result = nums.sort()
    print(result)
  6. Program 6

    nums = [10, 20, 30, 40, 50]
    print(nums[1:4], nums[::2])
  7. Program 7

    nums = [1, 2, 3]
    print(nums[3])
  8. Program 8

    nums = [4, 7, 4, 9]
    nums.remove(4)
    print(nums, nums.index(4))