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]
In questa pagina del sito puoi guardare il video online Python Tutorial 6 | Range Method della durata di ore minuti seconda in buona qualità , che l'utente ha caricato NaNdalal Dev 30 luglio 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 49 volte e gli è piaciuto 3 spettatori. Buona visione!