To convert a string to char-wise list, one way is to assign the string to an empty list. However, the physical process on the memory is unclear to me. Any help is appreciated.
An example
s = 'abc'
s_list = []
s_list[:5] = s
print(s_list)
The code will output:
['a', 'b', 'c']
Basically, I would like to understand:
- Why there is no out of index error when you try to do slicing s_list[:5] on an empty list? As a matter of fact, you can do s_list[:] or s_list[x:] or s_list[:x] (x can be any integer), it wouldn't raise any error.
- I would like to know what's happening at the assignment sign for
s_list[:5] = s
. Does Python do a automatic conversion from string to list before assign to s_list?