What will be the output of the following Python code? x = “abcdef” i = “a” while i in x: print(‘i’, end = “ ”)

Question: What will be the output of the following Python code?

x = “abcdef” 

i = “a” 

while i in x: 

    print(‘i’, end = “ ”)


(a) No output 

(b) i i i i i i ... 

(c) a a a a a a... 

(d) a b c d e 

Ans: (b) i i i i i i ... 

Here i i i i i i ... printed continuously because as the value of i or x is not changing, the condition will always evaluate to True. But also here we use a quotation marks on “i”, so here i treated as a string, not like a variable.

Comments

Popular posts from this blog

Diagonal Relationship between Beryllium and Aluminium || Relation between Beryllium and Aluminium

KVS CBSE Worksheets CHAPTER 1 Electric Charges and Fields Class 12

S-Block Elements || S-block element class 11 chapter 8 || Group 1A, 2A elements || S block elements chapter 8 notes class 11 || Chemistry ||

Electric Charges and Fields || Electrostatics Notes || Physics || Class 12 || Chapter 1 Notes Class 12 ||

Diwali 2020 || Deepawali 2020 || Happy diwali || Festival of lights || 2020 ||