CBSE Class 11 Computer Science
Question 63 of 91
String Manipulation — Question 8
Back to all questions 8
Question Question 2c
What will be the output produced by following code fragments?
x = "hello world"
print (x[:2], x[:-2], x[-2:])
print (x[6], x[2:4])
print (x[2:-3], x[-4:-2])Answer
Output
he hello wor ld
w ll
llo wo or
Explanation
x[:2] ⇒ he
x[:-2] ⇒ hello wor
x[-2:] ⇒ ld
x[6] ⇒ w
x[2:4] ⇒ ll
x[2:-3] ⇒ llo wo
x[-4:-2] ⇒ or