Python Practice › List Programs › Program 47
Add a prefix to every item
Write a Python program to insert a string at the beginning of every item.
Input
[1, 2, 3, 4, 5], "Sqa"
Output
['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']
Approach
- An f-string for each item.
Solution
print([f"Sqa{n}" for n in [1, 2, 3, 4, 5]])Output
['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']
Learn the concept
New to this topic? Read the lesson, then come back.