-
-
Save IndhumathyChelliah/ba62feb145fc6b6ae6593c4d6354ce1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creating dictionary | |
d={'name':'karthi', | |
'age':7, | |
'city':'chennai', | |
} | |
#Print only the keys | |
for i in d: | |
print (i) | |
''' | |
Output: | |
name | |
age | |
city | |
''' | |
#will print the (key,value) as a tuple | |
for i in d.items(): | |
print (i) | |
''' | |
Output: | |
('name', 'karthi') | |
('age', 7) | |
('city', 'chennai') | |
''' | |
#will print the key,value in the format specified | |
for i,j in d.items(): | |
print(i,j) | |
''' | |
Output: | |
name karthi | |
age 7 | |
city chennai | |
''' | |
#will print only the keys | |
for i in d.keys(): | |
print(i) | |
''' | |
Output: | |
name | |
age | |
city | |
''' | |
#will print only the values | |
for i in d.values(): | |
print(i) | |
''' | |
Output: | |
karthi | |
7 | |
chennai | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment