Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

range as a list in python

# range starts with 0
# Then goes till the number excluding it
print(list(range(4)))					# Output: [0, 1, 2, 3]
# If we give two numbers, first will be the start (including the number)
# Second will be the end (excluding the number)
print(list(range(1, 4)))				# Output: [1, 2, 3]

friends = ['John', 'Mary', 'Martin']
# If we get an integer as an output, we can use it to make a range function
# Here the len function gives us an integer, and we can use it for range function
print(list(range(len(friends))))		# Output: [0, 1, 2]
# Also we can demacate a gap by giving a third number
print(list(range(0, 10, 2)))			# Output: [0, 2, 4, 6, 8]
 
PREVIOUS NEXT
Tagged: #range #list #python
ADD COMMENT
Topic
Name
2+2 =