摘要: [root@localhost test1]# vim 19.py //add #!/usr/bin/python macaddr = '00:0C:29:D1:6F:E9' prefix_mac = macaddr[:-3] last_two = macaddr[-2:] plus_one = int(last_two, 16) + 1 new_last_two = hex(plus_one... 阅读全文
posted @ 2016-09-05 19:28 Frankiee 阅读(6017) 评论(0) 推荐(0) 编辑
摘要: [root@localhost test1]# vim 18.py //add #!/usr/bin/python with open('/proc/meminfo') as ll: for line in ll: if line.startswith('MemTotal'): total = line.split()[1] co... 阅读全文
posted @ 2016-09-05 18:53 Frankiee 阅读(223) 评论(0) 推荐(0) 编辑
摘要: /* 使用while循环遍历文件*/ [root@localhost test1]# vim 17.py //add #!/usr/bin/python ll = open('/tmp/1.txt') while True: line = ll.readline() if not line: break print line, [root@localh... 阅读全文
posted @ 2016-09-05 16:19 Frankiee 阅读(1553) 评论(0) 推荐(0) 编辑
摘要: /* while 是在有条件控制的情况下 进行的循环 */ [root@localhost test1]# vim 13.py //ADD #!/usr/bin/python n = 0 while True: if n == 10: break print n, 'hello' n += 1 [root@localhost test1]# pytho... 阅读全文
posted @ 2016-09-05 15:30 Frankiee 阅读(265) 评论(0) 推荐(0) 编辑
摘要: /* for...else 语句,当for循环正常结束后,才会执行else语句。 */ eg1: [root@localhost test1]# vim 11.py //ADD #!/usr/bin/python for i in xrange(10): print i else: print 'main end' [root@localhost test1]# pytho... 阅读全文
posted @ 2016-09-05 14:47 Frankiee 阅读(319) 评论(0) 推荐(0) 编辑
摘要: In [2]: list1 = [1,2,3,4] In [3]: for i in list1: ...: print i ...: 1 2 3 4 In [4]: for i in list1: print i, ...: 1 2 3 4 //range(头,尾,走多少步取值) In [7]: range(0,10) Out[7]: [0, 1, 2... 阅读全文
posted @ 2016-09-05 09:12 Frankiee 阅读(178) 评论(0) 推荐(0) 编辑