Python Practice › List Programs › Program 61
Capitalise the first and last letters
Write a Python program to make the first and last letters of each word uppercase, and also print every word in lowercase.
Input
["Learn", "python", "From", "Sqa", "tools"]
Output
['LearN', 'PythoN', 'FroM', 'SqA', 'ToolS'] ['learn', 'python', 'from', 'sqa', 'tools']
Approach
- Upper-case the ends and keep the middle.
Solution
words = ["Learn", "python", "From", "Sqa", "tools"]print([w[0].upper() + w[1:-1] + w[-1].upper() for w in words])print([w.lower() for w in words])Output
['LearN', 'PythoN', 'FroM', 'SqA', 'ToolS'] ['learn', 'python', 'from', 'sqa', 'tools']
Learn the concept
New to this topic? Read the lesson, then come back.