Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 14, 2020 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/ba62feb145fc6b6ae6593c4d6354ce1b to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/ba62feb145fc6b6ae6593c4d6354ce1b to your computer and use it in GitHub Desktop.
#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