How to Map Strings to Uppercase in Python

Loops through a list of strings and builds a new list with each string converted to uppercase.

Easy Python 3.9+ Aug 9, 2026 Algorithms & data structures 15 views 0 copies

Python code

7 lines
Python 3.9+
strings = ["hello", "world", "python", "skillset"]

uppercased = []
for s in strings:
    uppercased.append(s.upper())

print(uppercased)

Output

stdout
['HELLO', 'WORLD', 'PYTHON', 'SKILLSET']

How it works

The for loop iterates over each string in the original list. Inside the loop, s.upper() creates a new string with all characters converted to uppercase, which is then appended to uppercased. This is a classic mapping pattern: one input sequence, one output sequence, preserving order. The original list remains unchanged because strings are immutable and a new list is built.

Common mistakes

  • Forgetting to initialize `uppercased` before the loop, causing a NameError
  • Modifying the original list while iterating over it, leading to skipped items
  • Using `print()` inside the loop, which prints each item instead of a final list

Variations

  1. Use a list comprehension: `uppercased = [s.upper() for s in strings]`
  2. Use the `map()` function with lambda: `list(map(lambda s: s.upper(), strings))`

Real-world use cases

  • Normalizing user input like usernames or tags to uppercase before storing or comparing in a database.
  • Transform a list of city names fetched from an API into a consistent uppercase format for reporting.
  • Converting command names in a CLI tool to uppercase for case-insensitive dispatch.

Sponsored

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Algorithms & data structures

Related tutorials and quizzes for this topic.