Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Print Each Character

Print every character of entered text on its own line with Python. Students iterate directly over a string and see how spaces and empty input affect output.

BeginnerPhase 5 - Category 2: Character OperationsExample 3 of 10
print-each-character.py
1# Take string input
2s = input("Enter a string: ")
3
4# Print each character
5for char in s:
6 print(char)

Output

Enter a string: Hello
H
e
l
l
o

In this one

  • Iterate text directly
  • Use print's newline
  • Include spaces as characters

How it works

  1. 1

    Read s.

  2. 2

    Visit each character in input order.

  3. 3

    Print each on its own line.

Edge cases

Does a space get skipped?

Does a space get skipped?

No. It is printed as a character.

How many lines for abc?

How many lines for abc?

Three.

What's going on

A for loop supplies one character at a time without numeric indexes. print uses its default newline after every supplied value.

For cat, the output has three character lines. An ordinary space produces a line containing that space, which may look blank. Empty input has no characters, so the loop prints nothing; no final extra print is present.

Does a space get skipped? No. It is printed as a character.

How many lines for abc? Three.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Does this require indexing?

Pick an answer to check it.

Question 2

Does a space get skipped?

Pick an answer to check it.

Questions people ask

Does a space get skipped?

No. It is printed as a character.

How many lines for abc?

Three.

Does this require indexing?

No, direct iteration supplies characters.