Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
String Concatenation and Repetition
๐ Scenario: You are creating a simple text generator for greeting cards. You want to build a message by joining words and repeating some parts to make it more cheerful.
๐ฏ Goal: Build a program that creates a greeting message by concatenating strings and repeating parts of the message.
๐ What You'll Learn
Create a string variable with a greeting word
Create a string variable with a name
Create a variable for the number of exclamation marks
Concatenate the greeting and name with a space
Repeat the exclamation mark the specified number of times
Print the final greeting message
๐ก Why This Matters
๐ Real World
Creating dynamic text messages is useful in apps that send notifications, emails, or personalized greetings.
๐ผ Career
Understanding string operations is fundamental for software development, especially in user interface design and data formatting.
Progress0 / 4 steps
1
Create greeting and name variables
Create a string variable called greeting with the value "Hello" and another string variable called name with the value "Alice".
Python
Hint
Use the equals sign = to assign the text values to the variables.
2
Create exclamation count variable
Create an integer variable called exclamation_count and set it to 3.
Python
Hint
Remember to assign the number 3 to the variable exclamation_count.
3
Concatenate greeting and name with space
Create a string variable called message that concatenates greeting, a space " ", and name.
Python
Hint
Use the plus sign + to join strings. Remember to add a space between the words.
4
Add repeated exclamation marks and print
Add exclamation marks to message by concatenating message with "!" repeated exclamation_count times. Then print the final message.
Python
Hint
Use the * operator to repeat the exclamation mark string. Then use print() to show the message.
Practice
(1/5)
1. What does the + operator do when used with strings in Python?
easy
A. Joins two strings together into one
B. Repeats the string multiple times
C. Converts the string to uppercase
D. Splits the string into a list
Solution
Step 1: Understand the + operator with strings
In Python, + combines two strings by joining them end to end.