Generating a list without declaring it

Generating a list without declaring it

range() function is used in Python to generate a list without specifically declaring it.

Syntax of range() function is,

range(starting value,ending value,step value)

-----------------------

For example, below program 

list = range(0,9,1)
print(list)

prints a list starting with 0 with a step of 1. The list shall be up to 9. 9 shall not be part of the list.

--------------------------

For example, below program 

list = range(9)
print(list)

prints a list starting with 0 with a step of 1. The list shall be up to 9. 9 shall not be part of the list.

--------------------------

For example, below program 

list = range(0, 9)
print(list)

prints a list starting with 0 with a step of 1. The list shall be up to 9. 9 shall not be part of the list.

Post a Comment

0 Comments