Python Practice › List Programs › Program 38
Replace the first and last items
Write a Python program to replace the first and last numbers of a list with “SQA” and “Tools”.
Input
[12, 32, 33, 5, 4, 7]
Output
['SQA', 32, 33, 5, 4, 'Tools']
Approach
- Assign to index 0 and index -1.
Solution
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.