Post

Python Coding
Python Coding@clcoding·
What is the output of following Python Code?
Python Coding tweet media
English
0
0
0
45.2K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding Answer: 0 1 (on separate lines) Solution: Let's see what `range` does. If range is used with 2 integer arguments, here is how it works: range( start, stop ) gives an iterable from `start` up to `stop`. The `stop` is NOT included in the iterable. Thus, range(0, 2) is 0, 1 +
English
0
0
0
3.7K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding What would be range(0,0)? It would be empty. That's because the stop value (0) is not included in the range. As the start and the stop values are the same, there are no values included in the range. With that in mind, let's analyze the code. +
English
0
0
0
472
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding for i in range(0,2): ... Here i iterates over the values in range(0,2), which are 0 and 1. In the first iteration, print(i) prints 0 Next we have for j in range(0,0): ... range(0,0) is empty. A for loop over an empty iterable executes 0 times, ie, is ignored. +
English
0
0
0
445
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding Thus, the inner for-loop is ignored. That ends the first iteration of the outer loop. In the second iteration of the outer loop, i takes the value 1. print(i) this time prints 1 Again, the inner loop is ignored due to empty range. Snippet ends here. So, the net output: 0 1
English
0
0
0
250
Paylaş