Len和Print Len()之间的区别 [英] Difference between Len and Print Len()

查看:145
本文介绍了Len和Print Len()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始用Python进行数据分析,因为我没有从头开始学习Python,所以我觉得我错过了一些细微差别.

I've recently started doing data analysis in Python and since I didn't learn Python from scratch I feel I've missed a few nuances.

我注意到的一件事是,在我的一份报告中,我从CSV导入了一个数据集,将其作为字典放入其中,对其进行了处理,并试图打印其余条目.

One thing I noticed is in one of my reports I had imported a data set from a CSV, put it in as a dictionary, manipulated it and was trying to print the remaining entries.

我用过:

len(a)
len(b)
len(c)

执行此操作时,仅返回一个数字,因此我花费了大量时间调试我的代码.最后,我在网上找到了类似的代码,并尝试复制其语法.有效的更改是:

When I did this only one of the numbers was returning and so I spent a significant amount of time debugging my code. In the end I found similar code online and tried to copy its syntax. The change that worked was:

print len(a)
print len(b)
print len(c)

我试图了解这两个命令之间的区别.最初,我认为len只是打印出一个计数,但是我猜它有所不同吗?

I'm trying to understand the difference between the two commands. Initial I thought len just printed out a count, but I guess its something different?

len的计数只有记忆"吗?为什么我需要添加打印?

Does len only have 'memory' for one count? Why do I need to add print?

推荐答案

len(list)不打印任何内容,仅返回.如果您正在使用REPL(读取-评估-打印-循环),则它将打印返回的值并循环.因此,要打印多个,必须调用print.

len(list) does not print anything, it only returns. If you are using REPL (read - evaluate - print - loop) then it will print the returned value and loop. Therefore to print more than one you must call print.

这是方法文档

这篇关于Len和Print Len()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆