Tuesday, 23 April 2024

WHAT IS DICTIONARY


#  collectionof data items or key-values they are seperated commas or closed curly bracket.

dict = {"manan":"human", "cat": "animal"}
print(dict["manan"])

a = {
    10 : "manan",
    20 : "hanan",
    30 : "wahab"
}
print(a[10])

# 10 is a key or manan is a value.

info = {'name': 'manan', 'age':22, "eligible": True}
print(info)
print(info['name'])

#  if you want see the keys of  dictionary so

print(info.keys())
print(info.values())

#  for fumction in dictionary

for key in info:
    print(f"the value of {key} is {info[key]}")

#  method of dictionary is .update() he is used for combining multiple dictionaries.

c = {10:20, 30:40, 50:60}
d = {70:80, 80:90, 100:110}
c.update(d)
print(c)

# if you want delete the the key-value so use .pop()

d.pop(100)
print(d)

No comments:

Post a Comment

MAKE A CALANDER

  # 1.  convert calander year and month. your choice month or year , print while True :   import calendar   year = int ( input ( "P...