Course contentsShow
← Computer Science
Lesson 144 of 2,8724. Introduction to ProgrammingFree lesson

String Basics

Introduction to strings as sequences of characters for text representation.

String Basics

What you'll learn: How programs store and work with text using strings—sequences of characters grouped together.

What Is a String?

A string is a data type that represents text as a sequence of characters. Think of it like beads on a necklace: each bead is an individual character (which you learned about in the previous lesson), and the entire necklace is the string. While a char holds just one character like 'A', a string can hold zero, one, or many characters together: "Hello", "CS", or even "" (an empty string).

Why Strings Matter

In programming, we constantly work with text: usernames, error messages, file names, search queries, and more. Strings let us store, display, and manipulate this text data. Without strings, you could only work with individual characters one at a time—imagine trying to process someone's name letter by letter!

How Strings Work

Under the hood, a string is stored as a sequence of character values arranged in order. For example, the string "Cat" contains three characters in sequence: 'C', 'a', 't'. Different programming languages handle strings differently—some treat them as arrays of characters, others as special objects—but the core concept remains: a string is an ordered collection of characters treated as a single unit.

Strings are typically enclosed in double quotes ("like this"), distinguishing them from single characters in single quotes ('a').

Key Takeaway: Strings are sequences of characters that allow programs to represent and work with text as a unified piece of data rather than isolated individual characters.