Created
April 11, 2018 01:10
-
-
Save otayeby/fa5cdba2781818f5468227c7a94bc241 to your computer and use it in GitHub Desktop.
Using None to index all elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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