Dec-09-2019, 10:01 PM
(This post was last modified: Dec-09-2019, 10:02 PM by SvetlanaofVodianova.)
In the Zen of Python, it states:
Suppose I have the following
I don't like the
Quote:There should be one-- and preferably only one --obvious way to do it.
Suppose I have the following
list
:a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']I can slice it to print the last 4 digits in two ways:
# Both will print ['e', 'f', 'g', 'h'] print(a[-4:]) print(a[4:])Which is the Pythonic way of doing it?
I don't like the
a[4:]
because at first glance it looks like I'm printing the first 4 elements of the list
.