In Python, a string is text: an object of type str that stores a sequence of Unicode characters—names, messages, file paths, and almost every piece of text a program prints or reads.
You create strings with single quotes, double quotes, or triple quotes for multi-line text. Build messages with f-strings (f"Hi, {name}") or +. Strings are immutable: methods return a new string; they never change the original.
Write text = text.upper(). Calling text.upper() alone does not update text.
Prefer f-strings.
For everyday messages in Python 3.6+, f"..." is clearer than chaining + or older % formatting.
Syntax
Python Syntax
Common ways to create and inspect strings:
Python
literal = "Hello, Python!" # double or single quotes
name = "Ada"
hello = f"Hi, {name}!" # f-string
full = first + " " + last # + concatenation
length = len(text) # number of characters
ch = text[0] # first character (zero-based)
found = text.find("Py") # search (method)
Reference
Core Ideas
Ideas every Python string tutorial builds on:
Idea
Example
Remember
Literal
"Hello" or 'Hello'
Single and double quotes are equivalent
f-string
f"Hi, {name}"
Embed expressions in braces
Concatenation
a + " " + b
Creates a new string
Length
len(s)
Built-in function, not a method
Indexing
s[0], s[-1]
Zero-based; negatives count from the end
Immutability
s.upper()
Returns a new string
Code
Python Examples
Five short programs that define how strings work in a Python tutorial.
Example 1 — Create and print
Assign text and display it with print.
Python
language = "Python"
version = 3
print("Language:", language)
print("Version:", version)
print("Ready to learn strings!")
Output
Language: Python
Version: 3
Ready to learn strings!
How It Works
language stores a double-quoted literal.
print can take several values separated by commas.
A string is a str object that stores a sequence of Unicode characters—names, messages, paths, and more. You create strings with quotes: "Hello" or 'Hello', or with f-strings like f"Hi, {name}".
No. Strings are immutable. Methods like upper() and replace() return a new string. Assign the result if you need to keep it.
An f-string is a formatted string literal: put f before the quotes and embed expressions in braces, for example f"Score: {score}". It is the clearest everyday way to build messages in modern Python.
Use + for a few pieces: full = first + " " + last. For many pieces, prefer "".join(parts) or an f-string.
Practice the examples on this page, then open the String Methods index for capitalize(), find(), format(), and every other method guide in this Python tutorial series.