String

Data Types

A data type tells the program what kind of value something is and what can be done with it. Every value in a program has a type, and the type determines how the program stores and works with it.

For example, the number 42 and the text "42" look similar, but they are different types. You can add two numbers together, but adding two pieces of text just joins them into a longer string.

String

A string is a sequence of characters used to represent text. Names, messages, and user input are all stored as strings.

For a broader introduction to data types including strings, see Data Types.

Creating a String#

A string is written between quotation marks.

string name = "Odds and Evens";
name = "Odds and Evens"
let name = "Odds and Evens";

String Interpolation#

String interpolation lets you embed the value of a variable directly inside a string. Instead of building the string in pieces, you write the whole message in one place with placeholders for the variable values.