I have a question for Python beginners

Asked 2 years ago, Updated 2 years ago, 13 views


>>>li=[1,2,3,4,5,6,7]

>>>li[1:4]

[2,3,4]

>>>li[::2]

[1,3,5,7]

I'm learning the list

I can roughly guess that [1:4] is from 1 to 4.

All of a sudden [::2] came out... I don't know what you mean

Do you mean to float one in two compartments??? Hmm...

python

2022-09-22 10:42

1 Answers

If [A:B:C], A = starting point, included. B = final point, not included. C = step, interval. This is.

For example, [1:10:2] Ramen, Circulates at intervals of 2 from 1 to 9.

[::2] So you're going to cycle the indexed list at intervals of 2.

Note that [::-1] cycles the indexed list upside down.


2022-09-22 10:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.