理解dict.setdefault() in Python

  • Python Dictionary setdefault() Method

    The setdefault() method returns the value of the item with the specified key.

    If the key does not exist, insert the key, with the specified value.

    dictionary.setdefault(keyname, value)

    • keyname : Required. The keyname of the item you want to return the value from

    • value : Optional.

      ​ If the key exist, this parameter has no effect.

      ​ If the key does not exist, this value becomes the key’s value.

      ​ Default value None.

  • References

  1. w3schools
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章