Computer Science
What do you understand by mutability ? What does "in place" task mean ?
Python String Manipulation
7 Likes
Answer
Mutability means that the value of an object can be updated by directly changing the contents of the memory location where the object is stored. There is no need to create another copy of the object in a new memory location with the updated values. Examples of mutable objects in python include lists, dictionaries.
In python, "in place" tasks refer to operations that modify an object directly without creating a new object or allocating additional memory. For example, list methods like append(), extend(), and pop() perform operations in place, modifying the original list, while string methods like replace() do not modify the original string in place but instead create a new string with the desired changes.
Answered By
5 Likes
Related Questions
Write a Python script that traverses through an input string and prints its characters in different lines — two characters per line.
Discuss the utility and significance of Lists in Python, briefly.
Start with the list [8, 9, 10]. Do the following using list functions:
- Set the second entry (index 1) to 17
- Add 4, 5 and 6 to the end of the list
- Remove the first entry from the list
- Sort the list
- Double the list
- Insert 25 at index 3
What's a[1 : 1] if a is a string of at least two characters ? And what if string is shorter ?