1. 在python解释器中, _表示最后一个表达式的值,如:
- >>> s1 = 'Hello'
- >>> s1
- 'Hello'
- >>> s1 += ', Python!'
- >>> s1
- 'Hello, Python!'
- >>> _
- 'Hello, Python!'
第5行和第7行的打印值一样。
2.>>表示重定向,相当于cmd中的 >,如:
- >>> f = open('log.txt', 'a')
- >>> print >> f, 'this is a log file.'
- >>> f.close()
- >>> [line.strip() for line in open('log.txt', 'r')]
- ['this is a log file.']
- >>>
第2行中 >> 操作符就进行了重定向操作。