A sloppy story about Python's Slice

Moody

It's a shameful story because a result different from what I expected when a Python beginner was writing the following code was returned.

code

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']

Why are the results different?

I solved it in the following article. [Python] Summary of slicing operations It seems to be a specification.

But I'm not convinced

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. 0000.png

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'm too worried

I didn't have time to play the love live MV automatically

Recommended Posts

A sloppy story about Python's Slice
A story about using Python's reduce
A story about remodeling Lubuntu into a Chromebook
A story about machine learning with Kyasuket
A story about Python pop and append
A story about a 503 error on Heroku open
A story about operating a GCP instance from Discord
A story about Go's global variables and scope
A story about displaying article-linked ads on Jubatus
A story about implementing a login screen with django
A story about running Python on PHP on Heroku
A story about modifying Python and adding functions
A story about data analysis by machine learning
Escape from Python's virtual environment ~ A story about being trapped in a virtual environment I created ~
A story about predicting exchange rates with Deep Learning
A story about migrating entire Linux disk via SSH
A memorandum about matplotlib
A memorandum about Nan.
A story about making Hanon-like sheet music with Python
A story about trying a (Golang +) Python monorepo with Bazel
A story about kindergartens, nursery schools, and children's gardens
A story about reflecting Discord activity in Slack Status
A note about __call__
A story about struggling to loop 3 million ID data
A story about how theano was moved with TSUBAME 2.0
A note about subprocess
A story about changing the master name of BlueZ
A note about mprotect (2)
A story about a Linux beginner passing LPIC101 in a week
A story about a Linux beginner putting Linux on a Windows tablet
A story about stumbling through PATH after installing anaconda
A story that took time to understand python's argsort (memorial)
A story about creating a UNIX / Linux compatible OS from scratch
A story about how to specify a relative path in python.
A story about competing with a friend in Othello AI Preparation
A story about installing matplotlib using pip with an error
A little deeper story about blockchain, ticking the digital world
A story about an amateur making a breakout with python (kivy) ②
A story about how to deal with the CORS problem
A story about an amateur making a breakout with python (kivy) ①
A story about a war when two newcomers developed an app
A story about making a tanka by chance with Sudachi Py
A story about clustering time series data of foreign exchange
A story about a 40-year-old engineer manager passing "Deep Learning for ENGINEER"
A story about trying to implement a private variable in Python.
A story about a tragedy happening by exchanging commands in chat
A story about a GCP beginner building a Minecraft server on GCE
A story about a python beginner stuck with No module named'http.server'
A note about KornShell (ksh)
A memorandum about correlation [Python]
A note about TensorFlow Introduction
A memorandum about Python mock
A little more about FIFO
A note about [python] __debug__
A story about trying to automate a chot when cooking for yourself
A story about adding a REST API to a daemon made with Python
A story about a build error in a shared library that references libusb
A story about putting Chrome OS (not Chromium) on surface GO
A story about developing a soft type with Firestore + Python + OpenAPI + Typescript
A story about trying to run multiple python versions (Mac edition)
A story about wanting to think about garbled characters on GAE / P