On Thu, Dec 12, 2019 at 04:17:58PM +0530, Siddharth Prajosh wrote:
> Python slicing looks really weird.
I disagree that it looks weird. I think it looks beautiful.
> How do I explain *s=list(range(100));
> s[10:20] *gives you a part of the list.
The same way that you explain that the ^ operator does bitwise-XOR, that
the ** operator does exponentiation, that 0x10FF is an integer in
hexadecimal and that -23.84e15 is a float: you describe the syntax and
describe what it does.
Slicing syntax is one of the oldest, most fundamental parts of Python.
We're not going to change it. If you need to read Python code, you need
to be able to read slicing notation.
> Can we have an extra function for lists and string (and wherever slicing
> works) to explicitly mention that we're slicing??
Slicing syntax already *explicitly* tells us that we're slicing, just as
function call syntax explicitly tells us that we're calling a function,
and the `+` operator explicitly tells us that we're performing addition
(or concatenation).
We don't need a .slice() method for the same reason we don't need every
class to define a .equals() method. Syntax does the job fine.
If you can read function call notation:
something(a,b)
you should be able to read slicing notation:
something[a:b]
P.S. "explicit" doesn't necessary mean "spelled out in English words",
or "syntax that I like". Symbols can be explicit too. Syntax is explicit.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WRZLZRMPYSQYWEYE6ITEXPB3PTXB7ON5/
Code of Conduct: http://python.org/psf/codeofconduct/