编程札记

P

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)

阅读全文 ↗
P

Python3 字典 Get 方法

Python3 字典 Get 方法 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 27} print ("Value : %s" % dict.get('Age')) print ("Value : %s" % dict.get('Sex', "NA"))

阅读全文 ↗
P

Python3 字典 Fromkeys

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))

阅读全文 ↗
P

Python3 位运算符

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))

阅读全文 ↗