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]
On this page of the site you can watch the video online Python Tutorial 6 | Range Method with a duration of hours minute second in good quality, which was uploaded by the user NaNdalal Dev 30 July 2020, share the link with friends and acquaintances, this video has already been watched 49 times on youtube and it was liked by 3 viewers. Enjoy your viewing!