0% found this document useful (0 votes)
10 views

Python Practical Work

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Practical Work

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

#Name: Abhinav singh deora #course:BSC physics hons.

#Roll no.:24HPH2602
INPUT FOR DICTIONARY PROGRAM:--
#dictionary data structure

#Ex:● Write a program to make dictionary & use dict program.

#to make dictionary

dict1={'name': 'sam','age':26, 'country':'USA'} print(dict1)

dict2={'name':'Ria', 'course':'PCM', 'subject':['chem', 'phy', 'maths']} print(dict2)

dict3={'x':2*x for x in range (1,11)}

print(dict3)

#using dict function:

dict4=dict(brand='ford',model='mustang',color='orange')
print(dict4)

#ACCESS DICTIONARY ITEMS

print(dict1['name']) print(dict2['subject'])
print(dict2.values()) print(dict4.items())

#for update item in dictionary

dict4.update({'color':'white'}) print(dict4)

#add dictionary items

dict2.update({'subjects':['mech','thermal','quantum']}) print(dict2)

#remove dictionary items

dict2.pop('subject') print(dict2)

dict2.popitem()

print(dict2) del

dict1['name']

print(dict1)

OUTPUT OF DICTIONARY PROGRAM:--

You might also like