Python has no "primitive" data types in the sense Java or JavaScript use the term. A string is an instance of the built-in class str, so it is an object, but it is also immutable and behaves like a basic value. If your question is "is str a built-in, immutable type", the answer is yes.
This question was filed under JavaScript, but it is about Python, so this article covers Python. The sections below explain what "primitive" means here, what immutability does to your code, and how Python strings differ from JavaScript strings.
In Python, every value, including integers, booleans and strings, is an object with a type and an identity. There is no separate category of unboxed primitives.
Python documentation groups types as built-in types (int, float, bool, str, bytes, list, tuple, dict, set), and classes you define yourself. People who say "primitive" in Python usually mean the simple immutable built-ins: int, float, bool, str and bytes.
What matters in practice is whether an object can change after creation.
| Type | Mutable | Hashable (can be a dict key) |
|---|---|---|
int, float, bool | No | Yes |
str, bytes | No | Yes |
tuple | No (contents may be) | Yes if all items are |
list, dict, set | Yes | No |
Because strings are immutable, you cannot assign to a character, and every "modification" returns a new string.
A str is a sequence of Unicode code points. Since Python 3, text and binary data are separate types: str for text and bytes for raw data.
Unlike JavaScript, whose strings are UTF-16 code units, len() in Python counts code points, so an emoji counts as one. Grapheme clusters, such as some flags and accented sequences, can still span several code points.
Use == to compare string contents. The is operator compares identity, and CPython may reuse identical short strings, so is gives unreliable results.
For comparisons that should ignore case, use casefold() rather than lower(), since it handles more languages correctly.
Because each concatenation creates a new object, build large strings from pieces. Use f-strings for formatting.
CPython often optimises += on a string with a single reference, but join() is the portable, predictable choice.
"a" + b"b" raises a TypeError; decode the bytes first with .decode("utf-8").is to compare strings instead of ==.name.strip() alone does nothing.encoding="utf-8" to open() so behaviour is the same on every platform.Python does not use the term. A string is an immutable built-in object of class str.
No. Methods such as replace, strip and upper return new strings. For in-place edits, use a list of characters or io.StringIO.
No. A single character is a str of length 1.
Both are immutable. Python strings are sequences of code points with a separate bytes type, while JavaScript strings use UTF-16 code units and have no byte type.
Python treats all values as objects, so there are no primitives in the Java sense. A str is an immutable, hashable sequence of Unicode code points. Compare with ==, build with join() and f-strings, and keep text (str) separate from binary data (bytes).