square brackets after a function call

It means to extract the first item in the list/tuple return by the function.

In [1]: "this is a long sentence".split()
Out[1]: ['this', 'is', 'a', 'long', 'sentence']

In [2]: "this is a long sentence".split()[0]
Out[2]: 'this'

Leave a Comment