+ 1

Output?

What is the output of this code? for ch in “happy”: print(ch) break Output given: h Can anyone help me with this?

29th Jan 2018, 6:10 PM
Amith Varma
Amith Varma - avatar
4 Réponses
+ 1
at first iteration you take the first character 'h' and you print it. then you break the loop so iterations with other char are skipped, then program ends and just h was printed
29th Jan 2018, 6:11 PM
michal
+ 1
Why can’t the entire happy prints? Only the h first?
29th Jan 2018, 6:13 PM
Amith Varma
Amith Varma - avatar
+ 1
because you have that break there, it cancels the loop after first getting there delete it
29th Jan 2018, 6:14 PM
michal
+ 1
Ok thank you. I forgot that. Thanks alot for this😀
29th Jan 2018, 6:14 PM
Amith Varma
Amith Varma - avatar