Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Full stack web development using python

range

Saurabh Shukla (MySirG)


- Agendas
① What are iterables ?

iterates
② various

③ range

⑥ Accessing range elements

⑤ Practice
whatareiterables2.A-niterat.ae
object is
something that
contains a countable number of values
.

all the values


You can traverse through
from the end
beginning to .

Technically ,
in Python ,
an iterator is

an object ,
which implements the
of
iterator protocol ,
which consist

methods ites --
C) and _
-
next _
-
C)
-
_
variousdterabhes.ie
ange

list

tuple
• Str


bytes
.

byte array
-

• set

frozen set
• dict
ranges
is class

range a

is immutable sequence
range

contain only int type values


range
.
can

with

range contains sequence of integers


)
common difference ( Arithmetic Progression

✗=5 a
☐*☒

✗= 6
tlowtocreater-geobe.it?
8-
range ( beg ,
end
,
step ]
Example
23456789
range ( 1
,
10
,
1) I

↑ ←

Exclusive
common gap
inclusive

(2 8 2) 2 4 6
range , ,

8 G 4
range ( 10 ,
3
,
-2$ 10
otherwaystocreatesrangeobject
8-
range ( beg ,
end
,
step ]

① range ( end) beg -_ ◦ step __ I

② range ( beg , end) step =\


Accessing
- -
range elements
-
.

for e in 8 :

code
# e is an element of range
to
Write a
program print first n

natural numbers .

for ))) :
"

int ( input /
"
a in
range ( Enter anum

)
' '

print ( a -11 , end =


Write to print
a
program
squares first natural numbers
of n

for ))) :
"

int ( input /
"
a in
range ( Enter anum

print (4+1) )
' '
**2 end =
,
Write to print
a
program
first n even
natural numbers

in reverse order .

A- 5 to 8 6 4 2

for "D,⑧ 2)
range (2*int( input
"

a in Enter a mum
,
-

prmtf ( a. end
=
'
1)
Write a
program
to calculate

sum of first n multiples of


X .

You might also like