Reputation: 63
Sorry for the title I have no idea how to phrase what the code I found is doing.
I have this code I am trying to understand and I ran into this
data = file_data[sent:sent + to_send]
What does this do to the file_data list, and what is the proper name for this type of method?
Upvotes: 1
Views: 61
Reputation: 11134
It is actually slicing
your file_data
list. let's see it with an example,
>>> file_data = list(range(10))
>>> file_data
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> sent =2
>>> to_send = 3
>>> data = file_data[sent:sent + to_send] # file_data[2 : 2+3] => file_data[2 : 5]
>>> data
[2, 3, 4]
So, you will get a new list starting from the 2nd index till the (5-1)th -> 4th index.
Upvotes: 2