---
title: "Python String Operation Basics"
author: "hedajia"
date: "2014-07-03T21:37:36Z"
tags: []
categories: ["编程语言"]
slug: "python-string-operation-basics"
draft: false
lastmod: "2014-07-03T21:32:41Z"
id: 2088098
url: "https://hedajia.iteye.com/blog/2088098"
---

First of all,python strings can not be changed,because they are immutable.

- **String escape**

```
'Isn\'t,he said'
"Isn\"t,he said"

```

 

- **more readable string**

   

```
print("Isn\"t,he said")
```

- **do not want to escape**

```
print(r'C:some\name')
```

 

- **String concatenating**

 

```
"py" + "pyon"
"py" "pyon" #works
prefix="py"
prefix "thon" #does't work
3 * "un" "beat" #does't work
prefix + (3 * "un") #works
```

 

- **String indexing**

```
word="python"
word[0] #'p'
word[-1] #'n'
```

- **String slicing**

```
word="python"
word[0:2] #'py'
```

 

- **String length**

     the build-in function len() returns the length of a string.