Coding for All
Lesson 5: Joining Strings
Joining Strings Glue two pieces of text together with +.
1first = "Coding"
2second = "is fun"
3print(first + " " + second)
Terminal
$ python3 main.py
Coding is fun
Every line, explained
first = "Coding"
This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple. In Python you can write strings with "double" or 'single' quotes; both work. Pick one style and stick to it; this course uses double quotes.
second = "is fun"
This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple.
print(first + " " + second)
Using + between strings glues them together; this is called concatenation. + adds no space by itself, so we glue a " " (a space) in the middle. Without it you would get Codingis fun.