编程札记

P

Python3字典 CMP 方法

Python3字典 CMP 方法 #!/usr/bin/python3 dict1 = {'Name': 'Zara', 'Age': 7}; dict2 = {'Name': 'Mahnaz', 'Age': 27}; dict3 = {'Name': 'Abid', 'Age': 27}; dict4 = {'Name': 'Zara', 'Age': 7}; print "Return Value : %d" % cmp (dict1, dict2) print "Return Value : %d" % cmp (dict2, dict3) print "Return Value : %d" % cmp (dict1, dict4)

阅读全文 ↗
P

Python3 删除字典

Python3 删除字典 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # remove entry with key 'Name' dict.clear() # remove all entries in dict del dict # delete entire dictionary print ("dict['Age']: ", dict['Age']) print ("dict['School']: ", dict['School'])

阅读全文 ↗
P

Python3 赋值运算符

Python3 赋值运算符 #!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("Line 1 - Value of c is ", c) c += a print ("Line 2 - Value of c is ", c ) c *= a print ("Line 3 - Value of c is ", c ) c /= a print ("Line 4 - Value of c is ", c ) c = 2 c %= a print ("Line 5 - Value of c is ", c) c **= a print ("Line 6 - Value of c is ", c) c //= a print ("Line 7 - Value of c is ", c)

阅读全文 ↗
P

Python3 元组Tuple Len 方法

Python3 元组Tuple Len 方法 #!/usr/bin/python3 tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc') print ("First tuple length : ", len(tuple1)) print ("Second tuple length : ", len(tuple2))

阅读全文 ↗
P

Python3 元组Tuple CMP 方法

Python3 元组Tuple CMP 方法 #!/usr/bin/python3 tuple1, tuple2 = (123, 'xyz'), (456, 'abc') print cmp(tuple1, tuple2) print cmp(tuple2, tuple1) tuple3 = tuple2 + (786,); print cmp(tuple2, tuple3)

阅读全文 ↗
P

Python3 删除元组

Python3 删除元组 #!/usr/bin/python3 tup = ('physics', 'chemistry', 1997, 2000); print (tup) del tup; print "After deleting tup : " print tup

阅读全文 ↗
P

Python3 更新元组

Python3 更新元组 #!/usr/bin/python3 tup1 = (12, 34.56) tup2 = ('abc', 'xyz') # Following action is not valid for tuples # tup1[0] = 100; # So let's create a new tuple as follows tup3 = tup1 + tup2 print (tup3)

阅读全文 ↗
P

Python3 访问元组值

Python3 访问元组值 #!/usr/bin/python3 tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5, 6, 7 ) print ("tup1[0]: ", tup1[0]) print ("tup2[1:5]: ", tup2[1:5])

阅读全文 ↗