Python Dictionary in Hindi | Dictionary in python with examples

Python Dictionary in Hindi | Dictionary in python with examples

Python Dictionary – Dictionary Ek Data Structure hai joki aap bol sakte hai unordered collection of items in key : Value Pair | python dictionary in hindi me ham kuch data store kar sakte hai for example :- float , string , integer |

Python Dictionary in Hindi

Dictionary in python ko Or Accha Samanjh ne ke liye iske A To Z example dekhte |

Python Create Dictionary

Syntax :

variable name = { Curly braces }  

Aap upper diye gye syntax ko dekh sakte hai.

Python Dictionary In Hindi

How To Create python Dictionary

Example 1 :-

# dictionary create 
# 2 tarike ke se ham dictionary create kar sakte hai

# 1 method

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }
print(data)

# 2 method

data1 = dict(Name = 'Danish Ali' , age = 17) 
print(data1)

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

{'Name': 'Danish Ali', 'Age': 17}                                                                                             
{'Name': 'Danish Ali', 'age': 17}

Aap upper Diye gye output ko dekh kar program ko samanjh sakte hai.

Dictionary In Python

Example 2 :-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }

for i in data:      # print key
    print(i)

for i in data.values():       # print value
    print(i)


# items Method 

for i in data.items():
     print(i)

Output :-

# keys
Name                                                                                                                          
Age     
     
# values                                                                                                                 
Danish Ali                                                                                                                    
17 

#items method

('Name', 'Danish Ali')                                                                                                        
('Age', 17)

Aap Upper Diye gye output ko dekh kar program ko samanjh sakte hai.

python dictionary slicing

Dictionary Me Ham Data ko Kese Excess karte hai Ye Ham Example 3 me Dekhte hai |

Example 3:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }

print(data['Name'])
print(data['Age'])

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

Danish Ali                                                                                                                    
17 

Aap upper Diye gye Dictionary Slicing ke output ko dekh kar program ko samanjh sakte hai.

Python Dictionary Indexing

Dictionary Me Aap Indexing Nhi Kar Sakte hai Kyoki Dictionary unOrdered collection of items hai | Aap Example 4 me Dekh Skate hai iska program |

Example 4:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }
print(data[0])

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

Traceback (most recent call last):                                                                                            
  File "main.py", line 2, in <module>                                                                                         
    print(data[0])                                                                                                            
KeyError: 0 

Aap Dekh Sakte hai Program Error kyoki aap dictionary me indexing nhi kar sakte hai |

how to add data to empty Dictionary

Example 5:-

data  = {}     # empty dictionary
data['Name'] = 'Danish'       # add data in dict
data['Age'] = 17               # add data in dict

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

{'Name' : 'Danish' , 'Age' : 17}

Aap upper Diye gye output ko dekh kar program ko samanjh sakte hai |

python Dictionary in keyword

Agar Hame Ye Pata Karna Ho Ki Hamara Key & Value Dictionary Me hai Ya nhi to ye is example 6 me dekhte hai using in keyword |

Example 6:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }

if 'Name' in data:            # find key 
      print('present')
else:
     print('Not Present')

if 'Danish Ali' in data.values():     # find value          
      print('present')
else:
     print('Not Present')
     

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

present
present

Aap upper Diye gye output ko dekh kar program ko samanjh sakte hai |

Update Method In Dictionary In Python

Update Method 2 Dictionary ko add karke ek bana deta hai , Aap Example 7 dekh sakte hai |

Example 7:-

data1  = {'Name' : 'Danish Ali' , 'Age' : 17 }
data2  = {'Fav Movie ' : '3 idiots ' , 'Sport ' : 'Crickt' }

# update mathod

data1.update(data2)

print(data1)

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

{'Name': 'Danish Ali', 'Fav Movie ': '3 idiots ', 'Age': 17, 'Sport ': 'Crickt'}

Aap upper Diye gye Updating elements ke output ko dekh kar program ko samanjh sakte hai |

python del function

Python Delete Function :- Del Function ek index function leta hai or jo index number leta hai use hi delete karta hai |

Example 8:-

data1  = {'Name' : 'Danish Ali' , 'Age' : 17 }
del data[1]
print(data)

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

['Danish',29] 

Aap upper Diye gye del function ke output ko dekh kar program ko samanjh sakte hai |

Aap upper Diye gye Remove function ke output ko dekh kar program ko samanjh sakte hai |

python dictionary pop method

Python Pop Function :- Pop Function dictionary Me se ek Elements delete karta hai |

Example 9:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }

remove_pop = data.pop('Age')

print('Remove Data Using Pop Function is {} '.format(remove_pop))

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

17

Aap upper Diye gye Pop Function ke output ko dekh kar program ko samanjh sakte hai |

Get () Method in Dictionary

get() method ham dictionary me isliye istemal karte hai kyoki agar hame koi dictionary me se value print karani ho bina error ke |

Example 10:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }
get_data = data.get('Name')
print(get_data)    

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

Danish Ali

Aap upper Diye gye get method ke output ko dekh kar program ko samanjh sakte hai |

Python Clear

Python clear() Function :- clear Function Dictionary ko bilkul clear karta hai |

Example 11:-

data  = {'Name' : 'Danish Ali' , 'Age' : 17 }
data.clear()
print(data)

Aap Upper Diye Gye Program ko samanjh sakte hai.

Output :-

{}

Aap upper Diye gye clear() Function ke output ko dekh kar program ko samanjh sakte hai |

Dosto mujhe ummed hai ki aap python Dictionary with examples ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre or ha agar aap video bhi dekhna chahte hai to aap mere channel ko bhi subscribe kar sakte hai. channel ka link aapko home page par mil jayega |

Danish Ali

I Am a 1st Sem BCA Student & I have Skills C, C++ ,Python, HTML,CSS, Computer & Advance Hacking & Blogger & YouTuber.

Leave a Reply

Your email address will not be published. Required fields are marked *