Is the print() function in python considered a void function?

拈花ヽ惹草 提交于 2021-01-29 11:00:05

问题


As the title says, is the print() function in python a void function?

I thought the print() function returns and prints to screen what is passed into it. Now that I think about it, it seems like it doesn't return anything and is indeed a void function. Can someone verify this for me please? Thanks in advance!

I've tried the following:

some_variable = print()

print(some_variable) None


回答1:


It does not return a value, which is the same as returning None. You won't find it explicitly in the documentation as functions returning None simply omit documenting the return value.




回答2:


It doesn't return any value; returns None. you can consider as void

please referReturn Value from print()




回答3:


There are no void functions in Python. Functions without explicit return returns None, an object of type NoneType. Try print(type(None)) or print(None.__class__)

print prints to the text stream and doesn't return anything (returns None).

https://docs.python.org/3/library/functions.html#print



来源:https://stackoverflow.com/questions/58887944/is-the-print-function-in-python-considered-a-void-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!