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]"?

11th Dec 2016, 6:32 AM
YuHai
YuHai - avatar
5 Respuestas
+ 3
it isn't. nums.reverse() returns None. It just reverses array. try: nums.reverse() print(nums) or: print(nums[::-1])
11th Dec 2016, 7:12 AM
aruluth
aruluth - avatar
+ 3
print(nums[::-1])
27th Dec 2016, 12:38 PM
Dilan Perera
Dilan Perera - avatar
+ 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?
12th Dec 2016, 10:16 AM
YuHai
YuHai - avatar
+ 1
reverse (num)
27th Dec 2016, 1:31 PM
Ankit Kumar
Ankit Kumar - avatar
0
@aruluth is correct. You are printing the result of the reverse function call. Which is 'None' because it was successful.
11th Dec 2016, 9:44 AM
Kerrash
Kerrash - avatar