0
Why I get "None"?
Why I code: nums=[1,2,3,4] print(nums.reverse()) the answer is"None"? Isn't it supposed to be"[4,3,2,1]"?
5 Respuestas
+ 3
it isn't. nums.reverse() returns None. It just reverses array.
try:
nums.reverse()
print(nums)
or:
print(nums[::-1])
+ 3
print(nums[::-1])
+ 1
so...I can regard "nums.reverse()"as a process.It shows"None" because I cannot print a process instead of the main object"nums".In order to print"nums",I need to reverse "nums"first and then print it.
Do I get it wrong?
+ 1
reverse (num)
0
@aruluth is correct. You are printing the result of the reverse function call. Which is 'None' because it was successful.