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 :-

h : e : l : l : o : t : o :   : P : y : t : h : o : n : w : o : r : l : d :

(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 : )

  1. (b) is wrong
    it would be
    h : e : l : l : o : t : o : : P : y : t : h : o : n : w : o : r : l : d :

    ReplyDelete
    Replies
    1. there will be a blank space between to and Python b) h :e :l :l :o :t :o : :P :y :t :h :o :n :w :o :r :l :d :

      Delete
  2. all the answers are correct...

    ReplyDelete
  3. thankyou so much sir.

    ReplyDelete
  4. Output will be
    A)
    hellohellohello 123
    10 helloworld

    ReplyDelete

Post a Comment

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

Previous Post Next Post