Dictionaries in Python

Very Easy to use Dictionary in Python as compared to Java or other OOPS language.

Just need Eclipse Pydev Editor and thats its you are on the go.

Below is a sample code with few methods used.

 

#Play with Dictionary in Python.
from builtins import str
dict={‘Name’:’Ashish’,’age’:32}
print(dict[‘Name’])
print (dict[‘age’])
#Print Values in Dictionary
print(“Elements of the dicttionary are”,dict.values())
#Print Length of Dictionary
print(“Length of dictionary is “,len(dict))
#Return String Representation of dictionary
print(str(dict))
print(“Clearing contents of dictionary”,dict.clear())
if(len(dict)==0):
print(“Dictionary is empty”)
else:
print(“Dictionry is not empty”)
print(“Dictionary is empty:”,len(dict))

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s