Skip to content

Instantly share code, notes, and snippets.

@otayeby
Created April 11, 2018 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otayeby/fa5cdba2781818f5468227c7a94bc241 to your computer and use it in GitHub Desktop.
Save otayeby/fa5cdba2781818f5468227c7a94bc241 to your computer and use it in GitHub Desktop.
Using None to index all elements
"""
You have a function that takes an argument, this argument is the index of the last element you want to show from an
array. At some point you want found out that you want to use this function but grab all elements. Just pass None.
"""
def some_function(last_idx):
print(some_arr[:last_idx])
some_arr = range(100)
last_idx = 5
some_function(last_idx)
last_idx = None
some_function(last_idx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment