0
The question about functions
There are some examples showed below, when we use the function “x.count()”, we can just print it, but for other functions, like x.remove(), my confusion is why can't be just used in that way, print(x.remove())? Thx! x = [2, 4, 6, 2, 7, 2, 9] print(x.count(2)) x.remove(4) print(x) x.reverse() print(x)
2 odpowiedzi
+ 1
Charlie
As x is a list and remove is a function in List class which doesn't return anything.
So if you do like that you will get None.
Note:
1 - remove function is none returnable function, same reverse also
2 - count function returns number
+ 2
Depends of method declaration if it have any return value we can print it. Like count() method returns the count of 2, "x.count(2)" replaced with return value 3 like print(3).
remove method just remove that value from the list, doesn't return anything. So nothing will be printed (or) none will be printed.