> For the complete documentation index, see [llms.txt](https://denglj.gitbook.io/essential-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://denglj.gitbook.io/essential-go/02-basic-types/strings.md).

# 字符串

Go语言中字符串是一个不可变的字节(8-bit `byte`)序列。

这跟Python、C#、Java、Swift等编程语言不同，它们的字符串则是Unicode字符的序列。

字符串类型 `string`的[零值](/essential-go/02-basic-types/ling-zhi.md)是空字符串`""`。

### 字符串基本用法

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"fmt"
)

func main() {
	var s string // empty string ""
	s1 := "string\nliteral\nwith\tescape characters\n"
	s2 := `raw string literal
which doesnt't recgonize escape characters like \n
`
	fmt.Printf("sum of strings\n'%s'\n", s+s1+s2)
}
```

{% endtab %}

{% tab title="Output" %}

```
sum of strings
'string
literal
with	escape characters
raw string literal
which doesnt't recgonize escape characters like \n
'
```

{% endtab %}
{% endtabs %}

:point\_right: [点击此处](https://play.golang.org/p/4PZOuKBVj9U) :point\_left: 在编程操场执行上述代码。
