为什么这两个函数的 print len() 值不同?它们不一样吗?
此脚本打开的文件是一个包含三行文本的文本文件。我将它命名为 test.txt,里面是
Jack and Jill
gave up
they went home with no water
Run Code Online (Sandbox Code Playgroud)
代码:
def function2nd (filename):
target = open(theFile, 'r')
inData = target.read()
print inData
print len(inData)
target.close()
theFile = raw_input("What is the file name?\n>>")
function2nd(theFile)
def function3rd (filename):
target = open(theFile, 'r')
target.read()
print target.read()
print len(target.read())
target.close()
function3rd(theFile)
Run Code Online (Sandbox Code Playgroud)