问题
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