Python literals

Module 2 · Python literals · Lesson 4 of 6

Strings

A string — type str — is text: a sequence of characters wrapped in quotes. You've used them since your first print.

Text between quotes
"hello"
The quotes mark where the text starts and ends — they're not part of the value. The string is just hello.
'hi'is the same as"hi"
single or double quotes — your choice, just match them

Single quotes ('...') and double quotes ("...") both work — just open and close with the same kind. A handy rule of thumb: use double quotes when your text itself contains an apostrophe, so it doesn't end the string early.

Anything inside quotes is text, even digits: "123" is a string, not the number 123. They look the same on screen but Python treats them very differently — you can do maths with one and not the other. Try a few things:

Run it yourselfruns in your browser · Python
main.py

Notice + joins strings together and * repeats one — the same symbols mean something different for text than for numbers. Last of the four: true and false.