Return value of print statement in Python

Question:

In one book I found thatprint(print("any text")) returns the size of text inside the function. i.e. 8 Here

But in another book I found out that it returns None.

So which answer is true?
Or whether the 2nd answer is just an updated answer…?

Asked By: Lov Verma

||

Answers:

print() function doesn’t return anything (so it’s None). When you’re printing the output of a function which returns None, sure the output is None. So the 2nd book is correct.

>>> print(print())

None

If you want get the length of a string, you should use len() function:

>>> print(len("any text"))
8
Answered By: Remi Guan

In python return value of print is None. Maybe you are confusing it with C, where the "printf" function returns the number of characters printed.

Answered By: UglyCamel

At first innner print function is executed and the string in inner print function i.e, "any text" is printed.
After that it prints none

Answered By: Vigneshwara Reddy S
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.