Индексация в Python dictЭтот пример показывает, как получить и установить значения в словаре.
Создайте переменную словаря.
customers = py.dict
customers =
Python dict with no properties.
{}
Заполните переменную dict с именами клиента и номерами счета и отобразите результаты. Вывод зависит от вашей версии Python®.
customers{'Smith'} = int32(2112);
customers{'Anderson'} = int32(3010);
customers{'Audrey'} = int32(4444);
customers{'Megan'} = int32(5000);
customers
customers =
Python dict with no properties.
{'Smith': 2112, 'Megan': 5000, 'Audrey': 4444, 'Anderson': 3010}
Считайте номер счета для клиента Андерсона.
acct = customers{'Anderson'}
acct =
Python int with properties:
denominator: [1×1 py.int]
imag: [1×1 py.int]
numerator: [1×1 py.int]
real: [1×1 py.int]
3010