KnowledgeBoat Logo

Computer Science

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])

Python

Python String Manipulation

31 Likes

Answer

he hello wor ld
w ll
llo wo or

Working

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

Answered By

19 Likes


Related Questions