Hello, I am studying Python
I wanted to delete a specific index in the array using del, so I made the following code.
'str' object does not support item deletion.
There was no error before writing this sentence.
What's the problem? If you know it, I'd appreciate it if you could answer it ㅠ<
python error
Python cannot perform del
operations on elements of a particular index of a string.
In similar cases, tuple
or del
operations cannot be performed for elements in a particular index.
del
changes the target that holds the element by removing it.
list
is the type that can insert and remove elements, whereas str
and tuple
are the types that cannot insert and remove elements after being generated once.
The type that is created once and cannot be changed afterwards is called imutable type.
So how do we subtract only certain elements from file_data
?
Because the str
object is impossible, you must eventually create a new string object and substitute it in the file_data
variable.
The question you asked seems to be trying to erase the [019) range, so you can cut the 19 index to the end and put it in file_data
as shown below.
file_data = file_data[19:]
© 2024 OneMinuteCode. All rights reserved.