Professional Documents
Culture Documents
#1. Range
#1. Range
range
iterates
② various
③ range
⑤ Practice
whatareiterables2.A-niterat.ae
object is
something that
contains a countable number of values
.
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
•
with
•
✗=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 ]
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
)
' '
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