Concatenate Strings with Space

Write a Python lambda function that concatenates two strings, with a space in between. The function should accept two strings and return a single string.

Example 1:

Input: "Hello", "World"
Output: "Hello World"

Example 2:

Input: "Lambda", "Function"
Output: "Lambda Function"

You can use the + operator to concatenate strings in Python.

# Define the lambda function
concat_strings = lambda s1, s2: s1 + " " + s2

# Test the function
print(concat_strings("Hello", "World"))  # Output: "Hello World"
print(concat_strings("Lambda", "Function"))  # Output: "Lambda Function"

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!