Ex25: Why use pop(-1) instead of just pop()?

In the function print_last_word Zed used

word = words.pop(-1)

to pop off the last word.

I looked up the definition for pop() and it says that -1 is the default. So using

word = words.pop()

should give the same result.

Is it considered “good manners” to use the -1 here?

You are correct. Pop() default (last in list) is the most typical use case so this is a short cut.

1 Like

True believers might wave the Python style guide and proclaim that ‘explicit is better than implicit’, but I think in this case you’re fine. Everybody writes pop just like that. :wink:

1 Like

Thank you guys for your answers.