- 3

What is the output of this code?

x = 'cool' print(x[-1] + x[-2] + x[-4] + x[-3])

15th Jan 2022, 3:01 AM
Manoj C S
Manoj C S - avatar
3 Answers
+ 4
Pls remove all tags from your question, and include only one, with your code language. The answer depends on that. Also, tags are used to classify and search, so they should be informative. Pls explain your difficulty. Is it when determinimg the items from the indexes? Is it in understanding the + sign in the context? On "print" behaviour? I don't kmow what you need help for.
15th Jan 2022, 3:09 AM
Emerson Prado
Emerson Prado - avatar
+ 3
Manoj C S The answer is loco as you would know if you ran the code. This result is created through slicing of the string 'cool' x[-1] = l x[-2] = o x[-4] = c x[-3] = o Because the outputs of the string are characters, the + indicates concatenation which joins the characters together to create a new string 'loco'
15th Jan 2022, 3:13 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Output: loco
15th Jan 2022, 3:42 AM
CLAD
CLAD - avatar