【Python】Python - 一些Dictionaries的方法。Python Dictionary methods.
【Python】Python - 一些Dictionaries的方法。Python Dictionary methods.
Python 有一些內建的方法來使用dictionaries。
| Method | Description |
|---|---|
| clear() | 移除dictionary內的所有元素。 |
| copy() | 回傳已經copy後的dictionary。 |
| fromkeys() | 回傳一個dictionary有特定的key 與value 。 |
| get() | 回傳指定key的value。 |
| items() | 使用tuple的方式回傳dictionary內的key與value。 |
| keys() | 回傳一個list,裡面包含dictionary內的所有key。 |
| pop() | 刪除指定key的元素。 |
| popitem() | 移除最後一個新增的item。 |
| setdefault() | 回傳指定的key的value。如果key不存在則新增key與指定的value。 |
| update() | 對指定的key更新value。 |
| values() | 用list 回傳dictionary內所有的values。 |

留言
張貼留言