Strings
Computer scientists have a special word for text: strings. It's an old term – dating back to printing presses in the late 1890s! – that came about because all words are made up of letters that have been "strung together."
Anything can be a string when programming, just like anything can become text when you're typing.
Anything can be a string when programming, just like anything can become text when you're typing.
Turning Text into Strings
To make a string, surround your text (word, numbers, symbols, or a mix of all three) with either single (') or double (") quotes.
Here's a few examples:
Here's a few examples:
If you don't surround your word by double quotes or single quotes – say if you use double quotes on the left and single ones on the left, or you forget quotes on one side – you'll get a ParseError.
ParseErrors are Python's way of saying, "Hey! I was trying to read the word you were writing, but I got confused."
ParseErrors are Python's way of saying, "Hey! I was trying to read the word you were writing, but I got confused."
Leaving off the quotes entirely won't work either; you'll get a NameError. We'll talk more about NameErrors when we talk about variable containers, but for now, know that Python's confused when you type words without surrounding quotes.
Challenge!
Make a few strings of your own.