Added difference in range() between Python 2 and 3 (#20629)
Added the differences between the working methods of the range() function in Python 2 and 3, including the explanation of the "lazy" method of generating a list of numbers.
This commit is contained in:
		
				
					committed by
					
						 Christopher McCormack
						Christopher McCormack
					
				
			
			
				
	
			
			
			
						parent
						
							4e92b01111
						
					
				
				
					commit
					c056fc18dd
				
			| @@ -39,3 +39,11 @@ for i in range(3, 12, 2): | |||||||
| 9 | 9 | ||||||
| 11 | 11 | ||||||
|  ``` |  ``` | ||||||
|  |   | ||||||
|  |  #### Notes | ||||||
|  |  In Python 2, there are 2 functions for going through a range of numbers: range() and xrange(). | ||||||
|  |  Out of these functions, xrange() is the "lazy" function, meaning it generates numbers as necessary instead of actually creating | ||||||
|  |  a list of numbers and iterating through them. range(), on the other hand, makes an entire list of numbers and iterates through | ||||||
|  |  this list. This makes it a strain on the memory in the case of really long lists. | ||||||
|  |   | ||||||
|  |  In Python 3, the range() function mimics xrange() as the "lazy" variant, and xrange() itself has been removed. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user