简体   繁体   English

我得到“无”而不是结果

[英]I'm getting ''none'' instead of result

Hi im a beginner python user.嗨,我是初学者 python 用户。 I coded a thing just for practice but im getting ''none'' instead of the result.我编写了一个东西只是为了练习,但我得到的是“无”而不是结果。 code is like this: code代码是这样的:代码

i think im using str function wrong but i dont know how to fix it.我认为我使用 str function 错误,但我不知道如何解决。 thanks for your help感谢您的帮助

See, when you don't use the return keyword, a function returns None .看,当您不使用return关键字时, function 会返回None So when you print a function which returns None , Then None will be printing.因此,当您打印返回None的 function 时,将打印None

So, use the return keyword.因此,请使用return关键字。

def work_time(mathematic, chemistry, biology): 
    print(mathematic*2 + chemistry*1 + biology*(0.5))
    return mathematic*2 + chemistry*1 + biology*(0.5)
print("I will study " + str(work_time(1, 2,3) ) + " hours today")

I can't see an image or code but things that can result to none can be:- 1.Not returning a blue from function 2.Keeping a boolean inactive 3.Not defining codes我看不到图像或代码,但可能导致没有的事情可能是:- 1.未从 function 返回蓝色 2.保持 boolean 处于非活动状态 3.未定义代码

you should use return instead of print你应该使用return而不是print

def work_time(mathematic, chemistry, biology): 
    return mathematic*2 + chemistry*1 + biology*(0.5)
print("I will study " + str(work_time(1, 2,3) ) + " hours today")

none is telling you that the function is not returning a value so you must use the return keyword none 告诉您 function 没有返回值,因此您必须使用return关键字

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

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