Coding for All
Lesson 5: Joining Strings
Joining Strings Glue two pieces of text together with +.
1let first = "Coding"
2let second = "is fun"
3print(first + " " + second)
Terminal
$ swift main.swift
Coding is fun
Every line, explained
let first = "Coding"
let creates a constant: a named box whose value is set once and can never change. Swift people reach for let by default: if a value never needs to change, locking it down prevents accidents.
let second = "is fun"
let creates a constant: a named box whose value is set once and can never change. Swift people reach for let by default: if a value never needs to change, locking it down prevents accidents.
print(first + " " + second)
Using + between Strings glues them together (concatenation). + adds no space by itself, so we glue a " " (a space) in the middle.