简体   繁体   English

Python function 返回问题,返回 None

[英]Python function return problem, it returns None

i want to calculate sum of every digit.我想计算每个数字的总和。 For example, if we have number 134,we calculate 1+3+4 =8 and print it out.例如,如果我们有数字 134,我们计算 1+3+4 =8 并打印出来。 I did this in c, it works fine but when i try it in python it doesn't work.我在 c 中做了这个,它工作正常,但是当我在 python 中尝试它时它不起作用。 Here is my code: python code这是我的代码: python 代码

the problem in your code is that it has no return statement;您的代码中的问题是它没有return语句; by default, Python will return None .默认情况下, Python 将返回None

That being said, I would recommend you to add the code to the question in the next questions;话虽如此,我建议您在下一个问题中将代码添加到问题中; just as skrrrt commented:).正如 skrrrt 评论的那样:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM