Ejemplo 1: rango de Python en intervalos de 10
print("using start, stop, and step arguments in Python range() function")
print("Printing All odd numbers between 1 and 10 using range()")
for i in range(1, 10, 2):
print(i, end=', ')
Ejemplo 2: rango de Python
# range(start, stop, step)
# start = (can be ommitted) index to begin at (INCLUSIVE)
# stop = generate numbers up to, but not including this number (EXCLUSIVE)
# step = (can be omitted) difference between each number in the sequence
# idx: 0 1 2 3 4
# arr: 19 5 3 22 13
arr = [19,5,3,22,13]
# range(stop)
for i in range(len(arr)):
print(arr[i]) # prints: 19, 5, 3, 22, 13
# range(start, stop)
for i in range(2, len(arr)):
print(arr[i]) # prints: 3, 22, 13
# range(start, stop, step)
for i in range(0, len(arr), 2):
print(arr[i]) # prints: 19, 3, 13
# reverse:
for i in range(len(arr)-1, -1, -1):
print(arr[i])
Ejemplo 3: rango en python
#range(start,stop,step)
for x in range(0,20,2):
print(x)
Ejemplo 4: rango de Python
for i in range(0, 4):
print(i)
>0
>1
>2
>3
for i in range(4):
print(i)
>0
>1
>2
>3
for i in range(0, 4, 2):
print(i)
>0
>2
Ejemplo 5: rango en python
for i in range (start, step, stop):
dosomething()
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)