Python Practice › Loop Programs › Program 3

Build a string character by character

EasyLoop Programs · 3 of 90

Write a Python program that adds each character of a word from the user to an empty string.

Advertisement
Input
python
Output
Enter a word: python
python

Approach

  1. Start with an empty string and append each character with +=.

Solution

Python
word = input("Enter a word: ")result = ""for ch in word:    result += chprint(result)
Outputtyped input: python
Enter a word: python
python

Line by line

Line 2

The empty string is the starting value.

Lines 3-4

Each loop pass appends one character.

Learn the concept

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

More loop programs

← All 90 Loop Programs

Leave a Comment