0
li = ['random values', True]
li[:] = 'some text'

If I print this out, the list becomes ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't']. Why does this happen?

  • 2
    Does this answer your question? [What is the difference between list and list\[:\] in python?](https://stackoverflow.com/questions/4081561/what-is-the-difference-between-list-and-list-in-python) – mrtechtroid Feb 10 '21 at 04:40
  • Somewhat. Why is each letter split into a different value? – windows-weeb Feb 10 '21 at 04:44
  • You're assigning an iterable (the string) to a slice of the list (where the slice is the entire list). So the elements of the list become the individual characters of the string. – Tom Karzes Feb 10 '21 at 04:47

0 Answers0