In this video you will learn about python range method
Range method will help to initialize N elements at a time with start,stop and step value.
By default start value is 0, step(increment/decrement) value is 1 and stop value is user defined.
syntax:
variable=range( start value,stop value, step value)
consider the following 3 examples:
Example 1:
x=range(10)
so this will return values from 0-9 (10 is excluded) with step value 1
y=list(x)
print(y)
output:
[ 0,1,2,3,4,5,6,7,8,9 ]
Example 2:
x=range(10,20)
so this will return values from 10-19 (20 is excluded) with step value 1
y=list(x)
print(y)
output:
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
Example 3:
x=range(0,10,2)
so this will return values from 0-10(10 is excluded) with step value 2
y=list(x)
print(y)
output:
[ 0,2,4,6,8 ]
Example 4:
#Range method will help to decrement values as well
x=range(10,0,-1)
y=list(x)
print(y)
so this will return values from 10-1(0 is excluded) with step value -1
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Nesta página do site você pode assistir ao vídeo on-line Python Tutorial 6 | Range Method duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário NaNdalal Dev 30 Julho 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 49 vezes e gostou 3 espectadores. Boa visualização!