Lesson guide
What this Python exercise practices
Concatenate Strings is a beginner practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 10 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 10 minutes
Related public exercises
Summary
Learn how to join strings by concatenation and return the combined result.
Problem statement
Implement join_names(first, last) that returns a single string combining first and last name separated by a single space. The function should not modify the inputs aside from joining them with a space.
Task
Write a function that combines two name parts into a single string with a space between them.
Examples
Example - joining two names
Input
join_names('Ada', 'Lovelace')
Output
Ada Lovelace
Explanation
Join 'Ada' and 'Lovelace' with a space between them.
Input format
Two string parameters: first and last.
Output format
A single string that is the concatenation of first, a space, then last.
Constraints
Do not add extra spaces beyond one between the names. Handle empty strings by still returning the single space when appropriate (e.g., '' + 'Smith' -> ' Smith').
Samples
Sample input 0
join_names('John', 'Doe')
Sample output 0
John Doe
Explanation 0
Returns the two names joined by one space.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.