Why does this code print 5 and None? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does this code print 5 and None?

print((print(5)))

30th Oct 2021, 9:14 AM
Zahed Shaikh
Zahed Shaikh - avatar
2 Answers
+ 7
5 is printed by the inner print statement. None is printed by the outer print statement. The None results from the fact that the inner print doesn't return anything (None)
30th Oct 2021, 9:17 AM
Lisa
Lisa - avatar
+ 1
5 belongs to inner print so outputs it, then there is nothing in the outer print that results None inner print sends output to console but not to outer print try this print('Outer: ', 10, print('inner: ', 5))
30th Oct 2021, 10:50 AM
Krishnam Raju M
Krishnam Raju M - avatar