Python3 字典 Setdefault 方法
Python3 字典 Setdefault 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("Value : %s" % dict.setdefault('Age', None)) print ("Value : %s" % dict.setdefault('Sex', None)) print (dict)
阅读全文 ↗Python3 字典 Setdefault 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("Value : %s" % dict.setdefault('Age', None)) print ("Value : %s" % dict.setdefault('Sex', None)) print (dict)
阅读全文 ↗Python3 字典 Keys 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("Value : %s" % dict.keys())
阅读全文 ↗Python3 字典 Item 方法 #!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7} print ("Value : %s" % dict.items())
阅读全文 ↗Python3 字典 Has_Key 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("Value : %s" % dict.has_key('Age')) print ("Value : %s" % dict.has_key('Sex'))
阅读全文 ↗Python3 字典 Get 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 27} print ("Value : %s" % dict.get('Age')) print ("Value : %s" % dict.get('Sex', "NA"))
阅读全文 ↗Python3 字典 Fromkeys #!/usr/bin/python3 seq = ('name', 'age', 'sex') dict = dict.fromkeys(seq) print ("New Dictionary : %s" % str(dict)) dict = dict.fromkeys(seq, 10) print ("New Dictionary : %s" % str(dict))
阅读全文 ↗Python3 位运算符 #!/usr/bin/python3 a = 60 # 60 = 0011 1100 b = 13 # 13 = 0000 1101 print ('a=',a,':',bin(a),'b=',b,':',bin(b)) c = 0 c = a & b; # 12 = 0000 1100 print ("result of AND is ", c,':',bin(c)) c = a | b; # 61 = 0011 1101 print ("result of OR is ", c,':',bin(c)) c = a ^ b; # 49 = 0011 0001 print ("result of EXOR is ", c,':',bin(c)) c = ~a; # -61 = 1100 0011 print ("result of COMPLEMENT is ", c,':',bin(c)) c = a << 2; # 240 = 1111 0000 print ("result of LEFT SHIFT is ", c,':',bin(c)) c = a >> 2; # 15 = 0000 1111 print ("result of RIGHT SHIFT is ", c,':',bin(c))
阅读全文 ↗Python3 字典 Copy 方法 #!/usr/bin/python3 dict1 = {'Name': 'Manni', 'Age': 7, 'Class': 'First'} dict2 = dict1.copy() print ("New Dictionary : ",dict2)
阅读全文 ↗Python3 字典 Clear 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("Start Len : %d" % len(dict)) dict.clear() print ("End Len : %d" % len(dict))
阅读全文 ↗Python3 字典 Type 方法 #!/usr/bin/python3 dict = {'Name': 'Manni', 'Age': 7, 'Class': 'First'} print ("Variable Type : %s" % type (dict))
阅读全文 ↗Python3 字典 Str 方法 #!/usr/bin/python3 dict = {'Name': 'Manni', 'Age': 7, 'Class': 'First'} print ("Equivalent String : %s" % str (dict))
阅读全文 ↗Python3 字典 Len 方法 #!/usr/bin/python3 dict = {'Name': 'Manni', 'Age': 7, 'Class': 'First'} print ("Length : %d" % len (dict))
阅读全文 ↗