Python รวมฟังก์ชัน dictionary ต่อไปนี้:
| ลำดับ | ฟังก์ชันพร้อมคำอธิบาย |
|---|---|
| 1 | cmp(dict1, dict2) เปรียบเทียบสมาชิกของ dict ทั้งสอง |
| 2 | len(dict) ให้ความยาวรวมของ dictionary นี่จะเท่ากับจำนวน items ใน dictionary |
| 3 | str(dict) ผลิตการแทนค่าสตริงที่พิมพ์ได้ของ dictionary |
| 4 | type(variable) คืนค่าประเภทของตัวแปรที่ส่งผ่าน ถ้าตัวแปรที่ส่งเป็น dictionary จะคืนค่า dictionary type |
Python รวมเมธอด dictionary ต่อไปนี้:
| ลำดับ | เมธอดพร้อมคำอธิบาย |
|---|---|
| 1 | dict.clear() ลบสมาชิกทั้งหมดของ dictionary dict |
| 2 | dict.copy() คืนค่า shallow copy ของ dictionary dict |
| 3 | dict.fromkeys() สร้าง dictionary ใหม่ด้วย keys จาก seq และ values set to value |
| 4 | dict.get(key, default=None) สำหรับ key key คืนค่า value หรือ default หาก key ไม่อยู่ใน dictionary |
| 5 | dict.has_key(key) คืนค่า true หาก key ใน dictionary dict, false มิฉะนั้น |
| 6 | dict.items() คืนค่ารายการของ dict's (key, value) tuple pairs |
| 7 | dict.keys() คืนค่ารายการ keys ของ dictionary dict |
| 8 | dict.setdefault(key, default=None) คล้าย get() แต่จะตั้ง dict[key]=default หาก key ไม่อยู่ใน dict แล้ว |
| 9 | dict.update(dict2) เพิ่ม key-values pairs ของ dict2 เข้า dict |
| 10 | dict.values() คืนค่ารายการ values ของ dictionary dict |