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.
1# Take array of strings2n = int(input("Enter number of strings: "))3arr = []4for i in range(n):5 arr.append(input(f"String {i+1}: "))67# Concatenate8result = "".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
Collect responses as strings.
- 2
Call the empty-separator join on arr.
- 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.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum