FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonLearning/17.ForLoopInPython.py at Pythontuts · aditya0035/PythonLearning · GitHub
aditya0035
/
PythonLearning
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonLearning
/
17.ForLoopInPython.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (32 loc) · 1003 Bytes
Breadcrumbs
PythonLearning
/
17.ForLoopInPython.py
Copy path
File metadata and controls
37 lines (32 loc) · 1003 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
For loop allow us to iterate over iterables
"""
for
i
in
range
(
6
):
print
(
"{0}"
.
format
(
i
))
my_friends
=
[
"Jose"
,
"Jack"
,
"Jim"
]
for
friend
in
my_friends
:
print
(
friend
)
for
i
in
range
(
0
,
5
):
# here 0 is inclusive and 5 is exclusive
print
(
i
)
print
(
type
(
range
))
"""
Iterate over dictionary
when we iterate over dictionary using for loop it gives use a key
but when we iterate over dictionary using dictionaryobject.items()
it is a object which is array of tuples which contains key and value of dict
so it returns a tuples
"""
my_friends_dict
=
{
'Aditya'
:
10
,
'Abdul'
:
14
,
'Salil'
:
0
,
'Devashish'
:
5
,
'Shantanu'
:
10
}
print
(
my_friends_dict
.
items
())
#array of tuples
for
key
in
my_friends_dict
:
print
(
"Key:{0},Value:{1}"
.
format
(
key
,
my_friends_dict
[
key
]))
a
,
b
=
(
10
,
15
)
print
(
"a:{0},b{1}"
.
format
(
a
,
b
))
#this is called tuple destructuring
for
key
,
value
in
my_friends_dict
.
items
():
print
(
"key:{0},value:{1}"
.
format
(
key
,
value
))
Back
|
FazBrowse Home
|
New Git URL