Home > other >  The second line began to look not to understand
The second line began to look not to understand

Time:09-23

D={10: "x", rank 1: "wx," 2: "yx"}
D.s etdefault (1)
D.s etdefault (3)
[1] * len print (d (d))

The answer WXWXWXWX

The second line began to look not to understand, who's fairy the way?

CodePudding user response:

Setdefault () function is similar to the get () method, if the key doesn't exist in the dictionary, will add the key and the value is set to the default value,

 


D={10: "x", rank 1: "wx," 2: "yx"}
D.s etdefault (1) # 1 is the KEY, don't change the dictionary d
D.s etdefault (3) 3 # KEY does not exist, add 3: None, dictionary into {10:1: 'x' 'wx, 2:' yx, 3: None}

[1] * len print (d (d)) # d [1] is wx len (d) is 4
  • Related