I don’t understand where the "none" comes from in the output of my Python program.
Can anyone help me?
Program
def printColumn(x):
if type(x) is not list:
x = list(range(0,5))
for i in range(len(x)):
print(x[i])
x = [8,24,48,2,16]
print(printColumn(x))
Output
8
24
48
2
16
None
Thank you in advance
I just don’t understand why it doesn’t work
>Solution :
The function prints the values 8 thru 16.
But your main-level code has print(printColumn(x)), which means that the return value of the function is also printed. And since the function has no return statement, it returns None by default.
If you want to just call the function, without printing its result, just use printColumn(x) without the outer print() call.