Sobes.tech
Junior — Middle

What methods are available only for objects created as immutable data types?

sobes.tech AI

Answer from AI

Immutable data types in Python, such as strings (str), tuples (tuple), numbers (int, float), have methods that do not modify the object itself but return a new one.

Examples of methods available only for immutable objects:

  • str.upper(), str.replace() — return a new string without changing the original.
  • tuple.count(), tuple.index() — return information without modifying the tuple.

Unlike mutable types (e.g., lists), immutable types do not have methods like append(), extend() that modify the object in place.

Therefore, methods of immutable objects usually return new objects or values without changing the original object.