gpt4 book ai didi

python - 这条 Python 字符串切片语句中的两个冒号的用途是什么?

转载 作者:太空狗 更新时间:2023-10-29 17:28:01 27 4
gpt4 key购买 nike

例如,

str = "hello"
str[1::3]

我可以在 Python 文档的什么地方找到它?

最佳答案

sequences' description :

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.

关于python - 这条 Python 字符串切片语句中的两个冒号的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1013272/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com