Q. What will be the output produced by following code fragments?


(a)

y = str(123)

x = "hello" * 3

print (x , y)

x = "hello" + "world"

y = len(x)

print (y, x)


(b)

x = "hello" +

"to Python" +

"world"

for chr in x :

    y = chr

    print (y, ":", end = ' ')


(c)

x = "hello world"

print (x[:2], x[:-2], x[-2:])

print (x[6], x[2:4])

print (x[2:-3], x[-4:-2])



Answer =

(a)

Output: -

hellohellohello 123
10 helloworld
>>>

(b)

Output: - It give error that value of x is not defined well.

(c)

Output: -

he hello wor ld
w ll
llo wo or
>>>

7 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post