Strings in Python 3 are sequences of Unicode code points, immutable like tuples, meaning every 'modification', like .upper() or concatenation, actually returns a brand-new string rather than changing the original in place. They support indexing, slicing, iteration, and a large set of built-in methods for searching, splitting, and formatting, with f-strings (introduced in Python 3.6) now the standard way to interpolate values.
1Understanding Strings
Strings in Python 3 are sequences of Unicode code points, immutable like tuples, meaning every 'modification', like .upper() or concatenation, actually returns a brand-new string rather than changing the original in place. They support indexing, slicing, iteration, and a large set of built-in methods for searching, splitting, and formatting, with f-strings (introduced in Python 3.6) now the standard way to interpolate values.
Because strings are immutable, repeatedly concatenating one inside a loop with += rebuilds the whole string each time — for building up large text, collect pieces in a list and join them once at the end instead.
name = "world"
greeting = f"Hello, {name}!"
print(greeting)
print(greeting.upper())2Practical Example
Here is a real-world application of Strings showing how it is used in production Python code.
words = ["Python", "is", "fun"]
sentence = " ".join(words)
print(sentence)
print(sentence[:6])3Best Practices
Follow these guidelines when working with Strings:
1. Use f-strings for formatting instead of % formatting or .format(), for readability and slightly better performance
2. Use ''.join(pieces) instead of += in a loop when building a large string from many parts
3. Use triple-quoted strings for multi-line text or docstrings instead of manual newline concatenation
Tip: Because strings are immutable, repeatedly concatenating one inside a loop with += rebuilds the whole string each time — for building up large text, collect pieces in a list and join them once at the end instead.
name = "world"
greeting = f"Hello, {name}!"
print(greeting)
print(greeting.upper())