Concept Flow - String concatenation and repetition
Start with strings
Concatenate strings with +
Repeat string with *
Resulting string output
Start with strings, combine them using + to join, or * to repeat, then get the final string.
a = "Hi" b = "!" c = a + b r = c * 3 print(r)
| Step | Variable | Operation | Value | Output |
|---|---|---|---|---|
| 1 | a | Assign | "Hi" | |
| 2 | b | Assign | "!" | |
| 3 | c | Concatenate a + b | "Hi!" | |
| 4 | r | Repeat c * 3 | "Hi!Hi!Hi!" | |
| 5 | print(r) | Output r | Hi!Hi!Hi! |
| Variable | Start | After 1 | After 2 | After 3 | Final |
|---|---|---|---|---|---|
| a | "Hi" | "Hi" | "Hi" | "Hi" | |
| b | "!" | "!" | "!" | ||
| c | "Hi!" | "Hi!" | |||
| r | "Hi!Hi!Hi!" |
String concatenation uses + to join strings side by side. String repetition uses * with an integer to repeat the string. Example: 'Hi' + '!' = 'Hi!' 'Hi!' * 3 = 'Hi!Hi!Hi!' Use print() to see the final string.