SHREYA SARVAN MASANAM’s Post

𝗗𝗮𝘆 𝟭𝟬: 𝗣𝘆𝘁𝗵𝗼𝗻 𝗿𝗮𝗻𝗴𝗲 The range() function is used to generate a sequence of numbers. It is commonly used with loops, especially for loops. Basic syntax: range(start, stop, step) Step can be positive or negative Positive range (counting forward): range(1, 6) # 1, 2, 3, 4, 5 range(0, 10, 2) # 0, 2, 4, 6, 8 Negative range (counting backward): range(5, 0, -1) # 5, 4, 3, 2, 1 range(-1, -6, -1) # -1, -2, -3, -4, -5 Key points to remember: •The stop value is not included •start is optional (default is 0) •step is optional (default is 1) •range() is memory-efficient Common use cases: •Looping a fixed number of times •Generating indexes for lists •Creating number sequences Python range() uses lazy evaluation The range() function does not generate all numbers at once. Instead, it creates numbers only when they are needed. This behavior is called lazy evaluation. #python #programming #range

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories