Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
0
0
0
22.5K
Jacob Hess
Jacob Hess@Jacobhess·
The Python code snippet in the post uses a `for` loop with `range(3)` to iterate over 0, 1, and 2. When `i == 1` the `continue` statement skips printing 1, resulting in output "0 2" (option B). This quiz highlights `continue` which affects loop flow by bypassing remaining code in an iteration, a feature rooted in Python’s design to enhance control structures.
English
0
0
0
672
Premakumar Thevathasan (Prem Iyer)
Premakumar Thevathasan (Prem Iyer)@KumarT00623760·
@PythonPr The for loop iterates through the numbers 0, 1, and 2. When the value of i is 1, the if condition is met, and the continue statement is executed. Therefore, the print(i) statement is skipped when i is 1, and the value is not printed. Answer is:b 0 2
Premakumar Thevathasan (Prem Iyer) tweet media
English
0
0
0
733
Yash
Yash@buildwithyash·
@PythonPr It will be option B Because when you use continue statement it skip that iteration but does not break from loop
English
0
0
0
1K
Irek
Irek@Irek66790344·
@PythonPr Answer spoiler: It's B) 02! The continue statement skips the rest of the current iteration when i == 1, so only 0 and 2 get printed. The loop runs 3 times (i = 0, 1, 2), but when i equals 1, continue jumps straight to the next iteration without executing print(i).
English
0
0
0
71
Irek
Irek@Irek66790344·
@PythonPr Now here's a challenge FROM ME! Only true Python wizards will get this right!
Irek tweet media
English
0
0
0
121
Parth
Parth@Parth_jsx·
@PythonPr range(3) generates the numbers 0, 1, and 2,when i = 0, the condition i == 1 is false, so it prints 0; when i = 1, the condition is true, so continue skips the print statement and nothing is printed; finally, when i = 2, the condition is false again, so it prints 2 {B}
English
0
0
0
79
DGX
DGX@deepakgautamx1·
@PythonPr continue: when match found it skip body and goes to increment part. Basically skip the current particular index. My personal name to it as Index skipper. break: when match found it skip the whole loop. For current and upcoming indices. My personal name to it as Loop breaker @grok
English
0
0
0
15
Ahmad_sep
Ahmad_sep@merdas2000m·
@PythonPr 0 2 cuz we have continue for 1 and it's not printed
English
0
0
0
236
Kwame
Kwame@jr_molar·
@PythonPr B because, the program will skip 1 when it gets to it
English
0
0
0
152
deby
deby@debbysa23·
@PythonPr B. 02. Range start from zero (0), when i is 1 then skip to the next iteration. After that print 2. Range(3) means that iteration is less than 3. So the 3 does not include in the iteration
English
0
0
0
75
Paylaş