Python中文
首页
教程
问答
标签
搜索
登录
注册
计算len(str(sequence\u of \u numbers))vs len('sequence\u of \u numbers')
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在计算十万位数!,正好是456574。我是这样做的:</p> <pre><code>import math math.factorial(100000) </code></pre> <p>我把它的输出作为参数复制粘贴到<code>str()</code>并调用<code>len()</code>(这个数字很大,所以不能合理地粘贴到这里):</p> <pre><code>print len(str(<copy-pasted output from math.factorial()>)) </code></pre> <p>计算数字的数目花了一些时间!然后我在引号之间粘贴了相同的输出:</p> <pre><code>print len('<same copy-pasted output>') </code></pre> <p>这一次的结果是瞬间的。你知道吗</p> <p>有人能解释一下:<code>str()</code>方法比<code>' '</code>方法花费的时间更长吗,因为它们都表示字符串?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p><code>len(str(result))</code>首先从<code>result</code>创建一个字符串,然后计算它的长度。你知道吗</p> <p>另一方面,<code>len('result')</code>在引号中已经有了这个字符串,所以在运行代码之前基本上已经把它转换成了一个字符串。你知道吗</p> <p>我猜对大数做<code>str()</code>需要很多时间。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
在python3中使用Scipy pearsonr函数
3 回答
在Python3中使用scipy对多个lorentzian进行数据拟合
2 回答
在Python3中使用Script=argv
7 回答
在python3中使用selenium webdriver进行未解析的回溯
8 回答
在python3中使用selenium和phantomjs的网页截图之前如何等待?
9 回答
在Python3中使用Selenium和Requests模块从网页获取文件
4 回答
在python3中使用SIGINT终止函数
5 回答
在Python3中使用SIGTERM时,允许进程完成而不是中断
6 回答
在python3中使用smtplib发送XML内容
6 回答
在python3中使用socket库(RFCOMM模式)重新连接蓝牙设备?
1 回答
在python3中使用sounddevice和numpy编写wav文件
2 回答
在python3中使用Sqlalchemy插入MySQL查找类型错误的原因
8 回答
在python3中使用sqlite、pandas和sqlalchemy很难让rollback工作
2 回答
在python3中使用SQLite的FTS3/4
4 回答
在Python3中使用struct.calcsize()和len()有区别吗?
7 回答
在python3中使用substring函数时发生TypeError
6 回答
在Python3中使用Tkinter entry小部件写入串行设备
7 回答
在python3中使用tkinter时,如何在每次按下函数时获得运行该函数的按钮?
7 回答
在python3中使用tkinter的子帧
6 回答
在Python3中使用tryexcept块时,如何避免使用未初始化的变量?
6 回答