如何创建一个长正整数
如果这个问题对于那些比我更专业的人来说可能听起来有点微不足道,我很抱歉。如果我必须创建一个长正整数并找到零的数量(使用以下指令作为提示:将数字更改为字符串),你知道我应该做什么吗?实际上,这些是我为了解决这个问题而关注的一些概念和例子。
我不知道蓝色突出显示的线是否适合该作业。没有指定的其他信息(如果您想知道,我已经下载了 python 3.10,虽然在命令提示符面板上输入命令 python,但弹出正在使用的 python 版本是 3.6.6)。
我对这种问题感到非常抱歉,但我刚刚开始向 Python 迈出第一步。
谢谢
I am sorry if this question may sound a bit trivial for those who are more expert than me. If I have to create a long positive integer as well as find the number of zeros (with the following instruction as a hint: change the number to a string), do you know what I am supposed to do? Actually, these are some of the notions and examples that I'm focusing on to solve this problem.
I do not know whether the blue highlighted lines may be suitable for the assignment. There is no specified other info (if you are wondering, I have downloaded python 3.10, although typing the command python onto the panel of commands prompt, it pops up that the python's version in use is 3.6.6).
I am very sorry for this kind of question but I have just started moving my first step towards Python.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需借助其他模块即可查找整数中零的数量:
输出:
To find the number of zeroes in an integer without the aid of additional modules:
Output:
您可以使用
str()
将int
转换为str
,然后计算零的数量,这可以使用
re
中的findall()
函数来完成findall()
返回与第一个中的正则表达式匹配的所有出现的列表参数,这里 '0' 只会匹配零,第二个参数是要检查的字符串,这里我们使用str()
将数字转换为字符串。由于findall()
返回出现的列表,我们可以将该函数作为参数传递给len()
来获取出现的次数,您可以阅读更多此处
you can convert an
int
to astr
usingstr()
and then count the number of zeros,this can be done using the
findall()
function fromre
findall()
returns a list of all the occurrences that match the regex in the first argument, here '0' will only match a zero, the second argument is the string to check, here we pass the number cast as a string usingstr()
. asfindall()
returns a list of occurrences we can pass the function as an argument tolen()
to get the number of occurrencesyou can read more here