Python Practice › List Programs › Program 38

Replace the first and last items

EasyList Programs · 38 of 100

Write a Python program to replace the first and last numbers of a list with “SQA” and “Tools”.

Advertisement
Input
[12, 32, 33, 5, 4, 7]
Output
['SQA', 32, 33, 5, 4, 'Tools']

Approach

  1. Assign to index 0 and index -1.

Solution

Python
numbers = [12, 32, 33, 5, 4, 7]numbers[0] = "SQA"numbers[-1] = "Tools"print(numbers)
Output
['SQA', 32, 33, 5, 4, 'Tools']

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment