Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jun 14, 2020
Embed
What would you like to do?
#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