Hướng dẫn dùng items python python

Hàm Dictionary get[] trong Python

Hàm Dictionary keys[] trong Python

Hàm Dictionary items[] trong Python trả về tất cả các cặp key-value của một Dictionary

Nội dung chính

  • Cú pháp
  • Ví dụ hàm Dictionary items[] trong Python

Cú pháp

Cú pháp của items[] trong Python:

dict.items[]


Ví dụ hàm Dictionary items[] trong Python

Ví dụ sau minh họa cách sử dụng của hàm items[] trong Python.

dict1 = {'name': 'Viet', 'age': 22, 'address': 'Hanoi'}
 
print ["Cac cap key-value cua dict1: ", dict1.items[]]

Chạy chương trình Python trên sẽ cho kết quả:

Cac cap key-value cua dict1:  dict_items[[['name', 'Viet'], ['age', 22], ['address', 'Hanoi']]]

Hàm Dictionary get[] trong Python

Hàm Dictionary keys[] trong Python

Chủ Đề