Python – Dictionary

Python’s dictionaries are kind of hash-table type where it have key value. A Dictionary contains items separated by commas and enclosed within square curly braces ({  })Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.

Features of Python Tuples

  1. Unordered Lists
  2. Can change values and index after declaring elements
  3. Not allowed duplicate members
  4. Uses curly braces { }
  5. Can store different datatypes

Declaring Dictionary in Python

We can declared dictionary in two different wasy:

# First Way
dict1 = {}
dict1['one']="one"
dict1[1]=1

# Second Way
dict2 = {'two':'two',2:2}

Note – The plus (+) sign is the concatenation operator and the asterisk (*) is the repetition operator. For example −

dict1 = {}
dict1['one']="one"
dict1[1]=1

dict2 = {'two':'two',2:2}

print(dict1)
print(dict2)
print(dict1["one"])
print(dict1[1])
print(dict2.keys())
print(dict2.values())
Filed under: Python

No comment yet, add your voice below!


Leave a Reply