-1

Im working on coding bat questions. trying to rotate the lift one to the left. My code always return None as a result. what can i do?

**

def rotate_left3(nums): 
  a = nums.pop(0)
  return nums.append(a)

**

user2275365
  • 23
  • 1
  • 2
  • 6

1 Answers1

0

Because append is a method without a return value.

Any Python function without a return value will return None

Split the lines to return the appended list.

Or return nums + [a]

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • And more specifically, Python methods tend to be either functional (leave original object unmodified and return new object after transformation) _or_ have side-effects (mutate original object) and return nothing (`None` is implicit return when nothing else returned explicitly). They don't do both to avoid confusion over whether a method with a return might also mutate. There are exceptions, but the exceptions are usually returning some other object as part of an atomic mutation, not the object you called the method on (e.g. the `pop` methods on several types, `dict.setdefault`, etc.). – ShadowRanger Mar 09 '16 at 03:46