🧵 String
5th Grade 💻 Coding
A string is text in programming — a letter, a word, a sentence or even digits — written between quotation marks, like `"Hello"`.
The name comes from the idea that text is a “string” of characters, like beads on a thread. The quotation marks tell the computer where the text starts and ends, so it knows that “print” inside quotes is just a word and not a command. In Python you can use either double quotes or single quotes.
You can do special things with strings: join them ("Hello " + "world" gives "Hello world"), multiply them ("ha" * 3 gives "hahaha") and measure their length (len("hello") gives 5). Remember: "5" is a string, and 5 without quotes is a number — and they’re not the same thing.
For example
- Usernames, passwords, chat messages and website addresses are all stored as strings.
- Mia wrote
print("5" + "5")and got 55 — because she stuck two strings together. - A ZIP code like 02134 is usually stored as a string, not a number — you never do math with it, and as a number the 0 at the front would disappear.
📌 Remember: String = text in quotes. "5" is text; 5 is a number.
Quick quiz
What is a string?
What does len("hello") give?
What does "ha" * 3 give?