String
In one line
A string is an immutable sequence of characters in Python, written with single or double quotes.
In simple words
A string is a sequence of characters — text data. You create strings with quotes: 'hello' or "hello" (both work the same). Triple quotes '''...''' or """...""" allow multi-line strings.
Strings are immutable — you cannot change a character in place. Any operation that modifies a string (like replace or upper) returns a new string. Strings support indexing (s[0]), slicing (s[1:4]), concatenation (+), and repetition (* n).
Python strings have many useful methods: split(), join(), strip(), replace(), upper(), lower(), find(), and more. f-strings (f"{value}") embed expressions directly in strings.
Example
s = "Hello, World!"
print(len(s)) # 13
print(s.upper()) # HELLO, WORLD!
print(s.split(",")) # ['Hello', ' World!']
print(s[:5]) # Hello
name = "Alice"
print(f"Hi, {name}") # Hi, AliceStrings support len, methods like upper/split, slicing, and f-string formatting.
Common confusions
Confused with: list
The difference: A string is a sequence of characters and is immutable. A list is a sequence of any items and is mutable. You can change a list element but not a string character.
Related terms
Related Resources
Related Lessons
- Strings
Learn Python strings.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.