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

Carbohydrates || Lipids|| Proteins || Vitamins & Minerals || Fats and Oils

Himanshu chaudhary

2.0 gram of a metal burst in oxygen give 3.2 gram of its oxide. 1.42 gram of the same metal heat in steam give 2.27 gram of its oxide which toys shown by this data?

Vistas Chapter-2 The Tiger King || Revision Notes Class 12 Board Exams

Data Mining || Supervised vs. Unsupervised Techniques || Dimensionality Reduction || Partitioning Methods