Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

davidbrenton

  • 3 years ago

I don't understand the logic behind the use of two or more colons (Example Pset7 problem 19: result of str4[1:9:2])

  • This Question is Open
  1. davidbrenton
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I found the logic behind this problem on stackoverflow.com since my textbook hasn't yet arrived. I copied the logic from there and pasted below: s[i:j:k] slice of s from i to j with step k The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached (but never including j). If i or j is greater than len(s), use len(s). If i or j are omitted or None, they become “end” values (which end depends on the sign of k). Note, k cannot be zero. If k is None, it is treated like 1.

  2. bwCA
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    the info is also in the documentation

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy