-1

Please explain why this code behave like this.

x=["a","b","c"]
x+="de"
print (x)

output := ['a', 'b', 'c', 'd', 'e']

why it out like above output ? why not it doesn't output like the below lines ?.i know that we can append the "de" to output like this.how the "+" operators works in list ?

output := ['a', 'b', 'c', 'de']
khelwood
  • 55,782
  • 14
  • 81
  • 108
SOORYADEV
  • 39
  • 1
  • 7
  • `+=` on a list adds a sequence of items. `"de"` is a sequence of two items, `'d'` and `'e'`. – khelwood Mar 19 '21 at 16:55
  • 2
    Does this answer your question? [Python append() vs. + operator on lists, why do these give different results?](https://stackoverflow.com/questions/2022031/python-append-vs-operator-on-lists-why-do-these-give-different-results) – khelwood Mar 19 '21 at 17:00
  • Thank you, sir :-) – SOORYADEV Mar 19 '21 at 17:18

1 Answers1

0

In addition to @khelwood's reaction: if you would like to add 'de' using +=, you can do it like this:

x = ["a","b","c"]
x += ["de"]
print(x)