Page 279 - CITS - CSA - TP (Volume 2) - Hindi
P. 279
कं ूटर सॉ वेयर ए ीके शन - CITS
टा 3 : ने ेड श कोश
# Creating a nested dictionary
library = {
‘fiction’: {‘novels’: 50, ‘short stories’: 30},
‘non-fiction’: {‘history’: 20, ‘science’: 40}
}
# Accessing nested dictionary elements
print(“Library Book Information”)
print(“-------------------------”)
print(“Number of novels:”, library[‘fiction’][‘novels’])
print(“Number of science books:”, library[‘non-fiction’][‘science’])
ीकरण:
• श कोश ‘library’ ेिणयों (‘िफ न’, ‘नॉन-िफ न’) के साथ ने ेड है िजसम उप ेिणयाँ और उनकी सं ाएँ शािमल ह ।
• ने ेड त ों तक कई कुं िजयों का उपयोग करके प ँचा जा सकता है।
आउटपुट :
टा 4: श कोश िविधयाँ
student = {
‘name’: ‘SreeHari’,
‘age’: 20,
‘grade’: ‘A’
}
# Using dictionary methods
keys = student.keys()
values = student.values()
items = student.items()
print(“Keys:”, keys)
print(“Values:”, values)
print(“Items:”, items)
ीकरण:
• कुं िजयों, मानों और कुं जी-मान यु ों को पुनः ा करने के िलए मशः keys(), values(), and items() िविधयों का उपयोग िकया जाता है।
आउटपुट:
265
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 128

