+ 1
What does :: mean?
2 Antworten
+ 2
A default value is used if you omit one:
[0:9] is 0 to 9
[:9] is beginning to 9
[9:] is 9 to end
[1:9:2] is every second element starting at 1 through 9
[::] is beginning, to end, step size 1.
Step size 1 is assumed for the first 3, where it's omitted.
As for why you'd even want this:
b=print('text') (b is set to 'none')
my_list[b:b:b] still works as if b missing
So you could legally return none for variables indexing a list and not crash. That's a guess.
+ 1
if you have seen it concerning lists,
mylist = [2, 64, 78, 43, 22]
a = mylist[::]
a is a copy of your mylist. It means: from the start, to the end.
look after : slicing list