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

Concatenate Array of Strings

Concatenate a list of strings with an empty join separator. Students preserve each string's content and see why no new spaces appear between list entries.

BeginnerPhase 6 - Category 2: Array & String CombinationsExample 10 of 10
concatenate-array-of-strings.py
1# Take array of strings
2n = int(input("Enter number of strings: "))
3arr = []
4for i in range(n):
5 arr.append(input(f"String {i+1}: "))
6
7# Concatenate
8result = "".join(arr)
9print(f"Concatenated: {result}")

Output

Enter number of strings: 3
String 1: Hello
String 2: World
String 3: Programming
Concatenated: HelloWorldProgramming

In this one

  • Concatenate text elements
  • Preserve existing whitespace
  • Avoid unnecessary conversion

How it works

  1. 1

    Collect responses as strings.

  2. 2

    Call the empty-separator join on arr.

  3. 3

    Print the resulting concatenated string.

Edge cases

Does join add spaces automatically?

Does join add spaces automatically?

No. The separator is empty.

What if arr is empty?

What if arr is empty?

The result is an empty string.

What's going on

"".join(arr) combines every stored string in order. Unlike the integer-list example, these elements already are strings and need no conversion.

For red and blue, the result is redblue. Any space must already be inside an element; join inserts none. Empty elements contribute no characters, and an empty list produces empty text. The original list is not modified.

Does join add spaces automatically? No. The separator is empty.

What if arr is empty? The result is an empty string.

Quiz

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

Question 1

Why is str conversion unnecessary?

Pick an answer to check it.

Question 2

Does join add spaces automatically?

Pick an answer to check it.

Questions people ask

Does join add spaces automatically?

No. The separator is empty.

What if arr is empty?

The result is an empty string.

Why is str conversion unnecessary?

Input responses are already strings.