Python中文
首页
教程
问答
标签
搜索
登录
注册
Python不区分list和string的len()?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>例如,我有一个简单的数据框:</p> <pre><code>>> print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>当我尝试使用:</p> <pre><code>>> len(file[0]) 2 </code></pre> <p>但是对于第二个</p> <pre><code>>> len(file[1]) 9 </code></pre> <p>但是我想让第二个计算为<code>1</code>如何区分这两个?你知道吗</p> <ol> <li>我试过使用<code>.join()</code>,但它仍然计算为<code>9</code></li> <li>我试过<code>list.count</code>但是我出错了</li> </ol>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>freshgrad是字符串<br/> 所以len(文件[1])意味着你要计算这个的长度字符串。它是9。<br/> 如果文件[1]是一个包含freshgrad的列表,如['freshgrad'],len(文件[1])将是1。<br/></p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在乒乓球比赛中预测球的轨迹,对于AI球拍预测?
1 回答
如何在乒乓球游戏中阻止球
10 回答
如何在乘法和模中不乘空间?
10 回答
如何在乘法和除以2个不同的数字之间进行交换?
6 回答
如何在也是数据一部分的单个字符上拆分大字符串
2 回答
如何在乾草堆中找到針,有更好的解決方案嗎?
6 回答
如何在事件wxWidgets中传递自定义数据
2 回答
如何在事件中使用lambda i=i?
1 回答
如何在事件中心只接收最近的数据
9 回答
如何在事件发生之前保持云函数运行?
3 回答
如何在事件发生后使页面重定向到同一页面
4 回答
如何在事件回调之间保持python生成器的状态
10 回答
如何在事件处理程序(pythonsocket、sphinx)中保留docstring
3 回答
如何在事件处理程序中更改wxRichTextCtrl的光标位置?
6 回答
如何在事件处理程序中访问外部对象?
7 回答
如何在事件循环中将协程打包为正常函数?
4 回答
如何在事件循环之外运行协同程序?
2 回答
如何在事件循环结束时为并发未来的所有线程调用类方法?
2 回答
如何在事件文件中只保留一份摘要?
3 回答
如何在事件模板中添加事件
4 回答