理解dict.setdefault() in Python

    技术2024-07-06  62

    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

    w3schools
    Processed: 0.009, SQL: 9