Question discussion

What is the output of the following Python code?print("abcdef"[1:4], "abcdef"[::-2])

1328Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

print("abcdef"[1:4], "abcdef"[::-2])
  • Abcd fed
  • Bbcde fdb
  • Cbcd ace
  • Dbcd fdb
Correct answer: D

Explanation

The slice [1:4] gives "bcd", and [::-2] walks backwards in steps of two from the end: f, d, b.

Discussion 0

Nobody has replied yet. Start the discussion!