String slices

A segment of a string is called a slice. Selecting a slice is similar selecting a character:

The operator [n:m] returns the part of the string from the ‘n-eth’ character to the ‘m-eth’ character, including the first but excluding the last.

If you omit the first index (before the colon), the slice starts at the beginning of the string. If you omit the second index, the slice goes to the end of the string.

If the first index is greater than or equal to the second the result is an empty string. An empty sting contains no characters and has length 0, but other than that, it is the same as any other string.

from Thinking in Python

String slices,布布扣,bubuko.com

时间: 2024-08-06 20:08:08

String slices的相关文章

Go Slices: usage and internals

Introduction Go's slice type provides a convenient and efficient means of working with sequences of typed data. Slices are analogous to arrays in other languages, but have some unusual properties. This article will look at what slices are and how the

17 Go Slices: usage and internals

Go Slices: usage and internals 5 January 2011 Introduction Go's slice type provides a convenient and efficient means of working with sequences of typed data. Slices are analogous to arrays in other languages, but have some unusual properties. This ar

Span<T>

Introduction Span<T> is a new type we are adding to the platform to represent contiguous regions of arbitrary memory, with performance characteristics on par with T[]. Its APIs are similar to the array, but unlike arrays, it can point to either mana

我要翻译《Think Python》-002 贡献列表 &amp; 目录部分

PDF源文件地址 :  http://www.greenteapress.com/thinkpython/thinkpython.pdf 贡献列表 自从本书诞生之后,有超过上百个目光敏锐且有想法的读者给我发来了许多建议并指出了一些需要修正的地方.他们的热情和无私的奉献给了我巨大的帮助.如果你有任何建议或者发现需要修正的地方,请发邮件至:[email protected].如果您的建议被采纳,您的大名将会出现在我们的贡献人员列表(除非你本人过于低调拒绝承认).如果您发现文中的错误内容,敬请提供一下

How I Wrote a Modern C++ Library in Rust

https://hsivonen.fi/modern-cpp-in-rust/ Since version 56, Firefox has had a new character encoding conversion library called encoding_rs. It is written in Rust and replaced the old C++ character encoding conversion library called uconv that dated fro

Iterate over slices of a string

def iter_slices(string, slice_length): """Iterate over slices of a string.""" pos = 0 if slice_length is None or slice_length <= 0: slice_length = len(string) while pos < len(string): yield string[pos:pos + slice_length

A Tour of Go Making slices

Slices are created with the make function. It works by allocating a zeroed array and returning a slice that refers to that array: a := make([]int, 5) // len(a)=5 To specify a capacity, pass a third argument to make: b := make([]int, 0, 5) // len(b)=0

A Tour of Go Slicing slices

---恢复内容开始--- Slices can be re-sliced, creating a new slice value that points to the same array. The expression s[lo:hi] evaluates to a slice of the elements from lo through hi-1, inclusive. Thus s[lo:lo] is empty and s[lo:lo+1] has one element. packa

Go by Example: Slices

切片是Go语言的关键类型之一,它提供了比数组更加强大的队列相关接口. package main import "fmt" func main() { // 和数组不同的是,切片的类型仅由它所包含的元素决定. // 使用内置函数make可以创建一个长度不为零的切片. // 下面创建了一个长度为3,存储字符串的切片, // 切片元素默认为零值,对于字符串就是"". s := make([]string, 3) fmt.Println("emp:",