It's a shameful story because a result different from what I expected when a Python beginner was writing the following code was returned.
p=0
q=1
l=['a','b','c','d','e','f','g']
print(l[p:q])
['a']
By the way, the output result I expected as a beginner was as follows.
['a','b']
I solved it in the following article. [Python] Summary of slicing operations It seems to be a specification.
As a result of seeing the reference link, the intention of development is The description [a: b] seems to mean between a to b, which is more than a and less than b in Japanese.
However, at first glance, it seems to be a high hurdle to understand that this description is between a to b. If you look at the description [Ebisu: Roppongi], I would interpret it as from Ebisu to Roppongi, and I didn't think that the station to get off was Hiroo.
In the first place, a to b of slice means from index to len in the above image, so I found it difficult to interpret both sensuously and programmer-wise. As a result, I couldn't find any meaning in extracting a single element by specifying [index, len (some variable) of some variable] and spending time on research.
If anyone has an answer that there is a clear merit, I would appreciate it if you could let me know.
I didn't have time to play the love live MV automatically
Recommended Posts