为什么 write() 方法 returns IPython/Jupyter notebook 中字符串的长度?
Why does write() method returns the length of string in IPython/Jupyter notebook?
我在 Ipython 和 Jupyter notebook 中使用 write() 方法时看到了一些奇怪的(至少对我而言)行为:
In [1]: f = open('test.txt','w')
In [2]: f.write("This is the first line")
Out[2]: 22
它实际上是返回我在文件中写入的字符串的长度。
我对这种行为有点好奇。有人可以解释为什么会这样吗?
这不是 IPython 特有的内容。
write()
方法returns写入的字符数。
你看到这个的原因是因为你正在使用解释器。
我在 Ipython 和 Jupyter notebook 中使用 write() 方法时看到了一些奇怪的(至少对我而言)行为:
In [1]: f = open('test.txt','w')
In [2]: f.write("This is the first line")
Out[2]: 22
它实际上是返回我在文件中写入的字符串的长度。
我对这种行为有点好奇。有人可以解释为什么会这样吗?
这不是 IPython 特有的内容。
write()
方法returns写入的字符数。
你看到这个的原因是因为你正在使用解释器。