Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

convert range into list python

l = [*range(5)]     # (*) is unpacking operator. "Intro to Python", p137
print(l)
#[0, 1, 2, 3, 4]

l1 = list(range(5))     # call list __init__
print(l1)
#[0, 1, 2, 3, 4]

l2 = [i for i in range(5)]      #list comprehension
print(l2)
# [0, 1, 2, 3, 4]
 
PREVIOUS NEXT
Tagged: #convert #range #list #python
ADD COMMENT
Topic
Name
9+5 =