Learn Python
>>> variables_data_types.strings

Strings in Python

#concept

A string (str) is Python's type for text — any sequence of characters wrapped in quotes. Strings are immutable, meaning once created they can never be changed in place; every operation that seems to "modify" a string actually builds and returns a brand new one, leaving the original untouched.

Strings also behave as sequences, so individual characters can be accessed by position (indexing), the same way items in a list can be — a connection that becomes clearer once slicing is covered later in this course.

#how it works
1

Create a string

Wrap text in single, double, or triple quotes.

2

Access characters by index

my_string[0] gets the first character — indexing starts at 0.

3

Combine strings

Concatenate with +, or repeat with *.

4

Methods return new strings

Because strings are immutable, calls like .upper() or .replace() return a new string rather than changing the original.

5

Measure length with len()

Counts every character, including spaces and punctuation.

#example
greeting = "Hello"
print(greeting[0])
print(greeting + ", World!")
print(greeting.upper())
print(greeting)
print(len(greeting))
Output
H
Hello, World!
HELLO
Hello
5
1greeting[0] accesses the character at index 0 — Python indexes strings starting from 0, not 1.
2+ concatenates two strings into a new one.
3.upper() returns an all-uppercase copy of the string.
4Printing greeting again afterward shows it is unchanged — .upper() never modified the original, since strings are immutable.
5len() counts the characters, including the letters and any spaces.
#use cases
Storing and displaying any text — names, messages, file contents, user input
Building formatted output for reports, logs, or user interfaces
Parsing and validating text input, like checking a password's length
Searching within text using methods like .find() or the in operator

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.