Back to Lessons
BeginnerStrings
String Concatenation
lesson_16.py
>>> ## Concept
String concatenation is the process of joining two or more strings together. In Python, you can use the `+` operator to accomplish this. This is a very handy feature when you want to print messages or combine data in your programs.
Here’s a simple example:
```python
first_name = "John"
last_name = "Doe"
full_name = first_name + " " + last_name
print(full_name)
```
In this example, the variable `full_name` will hold the combined value "John Doe". Notice how a space is added between the first and last names by using " ". You can use the `+` operator to combine any number of strings, just make sure each string is surrounded by quotation marks.
## Practice
For this exercise, you need to practice string concatenation by modifying the starter code. Create two string variables: `name` with the value "Alice" and `greeting` with the value "Hi". Then, use the `+` operator to combine these strings with a space in between and output the result.
Here’s how you can get started:
```python
# Your code here
name = ""
greeting = ""
```
To pass the test, ensure that your program prints "Hi Alice" exactly, including the space between the words.
Code Editor
Sign in to submit your answer and earn XP.