I have just come across an interesting case, I think.
I was trying to reverse my list and then print output using the print()
function.
Here are the two ways I have tried:
1. Printing directly:
x = [2.0, 9.1,12.5]
print(x.reverse())
output: None
2. Using f string:
x = [2.0, 9.1,12.5]
print(f"The reverse of x is {x.reverse()}")
output: The reverse of x is None
The output from both methods is None
as you can see above.
Can anyone explaing why both methods produce None
?
P.S. I know that the this method works and prints revered list
x.reverse()
print(x)
but I am not intereseted in this? I want to find out why both methods above produce None
.