Dictionary methods (get, keys, items)
Në shqip: Metodat e fjalorit
ShpjegimiSQ
Fjalorët në Python kanë metoda të dobishme: get() merr një vlerë pa gabim nëse çelësi s'ekziston, keys() jep çelësat, values() vlerat, dhe items() çiftet çelës–vlerë — shumë praktike në një cikël for.
EnglishEN
Python dictionaries have handy methods: get() fetches a value without an error if the key is missing, keys() gives the keys, values() the values, and items() the key–value pairs — very handy in a for loop.
Si ta mendosh
Si lista e telefonit: mund të shohësh vetëm emrat, vetëm numrat, ose të dyja bashkë — dhe po kërkove dikë që s'është, thjesht s'del asgjë.
Lexoje në anglisht
Like your phone contacts: you can view just the names, just the numbers, or both together — and if you look up someone who isn't there, you just get nothing.
Shembull kodipython
notat = {"Arta": 5, "Dren": 4}
print(notat.get("Ilir", "s'ka notë"))
for emri, nota in notat.items():
print(emri, nota)