fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,31 @@
---
title: String Methods
localeTitle: 字符串方法
---
**TODO `string`基本信息**
[Python文档 - 字符串](https://docs.python.org/3/library/stdtypes.html#strings)
**创建:**
使用一对引号或撇号创建空`string`
```shell
>>> new_string = ''
>>> type(new_string)
<class 'string'>
>>> len(new_string)
0
```
[Python文档 - 有关字符串的更多信息](https://docs.python.org/3/tutorial/datastructures.html#more-on-strings)
* `string.find('you')`返回找到子字符串的最低位置。
* `str.join(iterable)`使用指定的字符串连接`iterable`所有元素。
* `str.replace(old, new, max)`方法用于将字符串`old`替换为字符串`new` ,总计`max`次数。此方法返回带有替换的字符串的新副本,并且原始`str`不变。
* `string.split(separator, maxsplit)`返回由分隔字符串的列表`separator` ,可选`maxsplit`的次数,如果没有指定,该字符串将在所有情况下被分裂`separator`
* `string.strip(to_strip)`返回从字符串的开头和结尾删除`to_strip`的字符串。如果未指定`to_strip` ,则将删除所有空白字符。

View File

@@ -0,0 +1,33 @@
---
title: String Find Method
localeTitle: 字符串查找方法
---
## 字符串查找方法
在Python中`find()`字符串中的子字符串有两种选择: `find()``rfind()`
每个都将返回找到子字符串的位置。两者之间的区别在于`find()`返回最低位置, `rfind()`返回最高位置。
可以提供可选的开始和结束参数,以限制在字符串的部分内搜索子字符串。
例:
```shell
>>> string = "Don't you call me a mindless philosopher, you overweight glob of grease!"
>>> string.find('you')
6
>>> string.rfind('you')
42
```
如果未找到子字符串,则返回-1。
```shell
>>> string = "Don't you call me a mindless philosopher, you overweight glob of grease!"
>>> string.find('you', 43) # find 'you' in string anywhere from position 43 to the end of the string
-1
```
更多信息:
字符串方法[文档](https://docs.python.org/3/library/stdtypes.html#string-methods) 。

View File

@@ -0,0 +1,78 @@
---
title: String Join Method
localeTitle: 字符串连接方法
---
## 字符串连接方法
`str.join(iterable)`方法用于连接具有指定字符串`str``iterable`所有元素。 如果iterable包含任何非字符串值则会引发TypeError异常。
`iterable` :字符串的所有迭代。可以是字符串列表,字符串元组甚至是普通字符串。
#### 例子
1`":"`加入字符串ist
```python
print ":".join(["freeCodeCamp", "is", "fun"])
```
产量
```shell
freeCodeCamp:is:fun
```
2`" and "`加入一个字符串元组
```python
print " and ".join(["A", "B", "C"])
```
产量
```shell
A and B and C
```
3在字符串中的每个字符后面插入一个`" "`
```python
print " ".join("freeCodeCamp")
```
输出:
```shell
free C ode C amp
```
4加入空字符串。
```python
list1 = ['p','r','o','g','r','a','m']
print("".join(list1))
```
输出:
```shell
program
```
5加入套装。
```python
test = {'2', '1', '3'}
s = ', '
print(s.join(test))
```
输出:
```shell
2, 3, 1
```
#### 更多信息:
[字符串连接的Python文档](https://docs.python.org/2/library/stdtypes.html#str.join)

View File

@@ -0,0 +1,41 @@
---
title: String Replace Method
localeTitle: 字符串替换方法
---
## 字符串替换方法
`str.replace(old, new, max)`方法用于将字符串`old`替换为字符串`new` ,总计`max`次数。此方法返回带有替换的字符串的新副本。原始字符串`str`保持不变。
#### 例子
1.`"WAS"`替换所有出现的`"is"` `"WAS"`
```python
string = "This is nice. This is good."
newString = string.replace("is","WAS")
print(newString)
```
产量
```python
ThWAS WAS nice. ThWAS WAS good.
```
2.`"WAS"`替换前两次出现的`"is"` `"WAS"`
```python
string = "This is nice. This is good."
newString = string.replace("is","WAS", 2)
print(newString)
```
产量
```python
ThWAS WAS nice. This is good.
```
#### 更多信息:
阅读[Python文档中](https://docs.python.org/2/library/string.html#string.replace)有关字符串替换的更多信息

View File

@@ -0,0 +1,86 @@
---
title: String Split Method
localeTitle: 字符串拆分方法
---
`split()`函数通常用于Python中的字符串拆分。
#### `split()`方法
模板: `string.split(separator, maxsplit)`
`separator` :分隔符字符串。您可以根据此字符拆分字符串。例如。它可能是 ” ”, ”:”, ”;”等等
`maxsplit` :基于`separator`拆分字符串的次数。如果未指定或-1则根据`separator`所有匹配项拆分字符串
此方法返回的分隔字符串的列表`separator`
#### 例子
1在空格上拆分字符串“”
```python
string = "freeCodeCamp is fun."
print(string.split(" "))
```
输出:
```python
['freeCodeCamp', 'is', 'fun.']
```
2用逗号分隔字符串
```python
string = "freeCodeCamp,is fun, and informative"
print(string.split(","))
```
输出:
```python
['freeCodeCamp', 'is fun', ' and informative']
```
3未指定`separator`
```python
string = "freeCodeCamp is fun and informative"
print(string.split())
```
输出:
```python
['freeCodeCamp', 'is', 'fun', 'and', 'informative']
```
注意:如果未指定`separator`符,则会删除**所有**空格的字符串
```python
string = "freeCodeCamp is fun and informative"
print(string.split())
```
输出:
```python
['freeCodeCamp', 'is', 'fun', 'and', 'informative']
```
3使用`maxsplit`拆分字符串。这里我们将字符串拆分为两次:
```python
string = "freeCodeCamp is fun and informative"
print(string.split(" ", 2))
```
输出:
```python
['freeCodeCamp', 'is', 'fun and informative']
```
#### 更多信息
查看[有关字符串拆分](https://docs.python.org/2/library/stdtypes.html#str.split)的[Python文档](https://docs.python.org/2/library/stdtypes.html#str.split)

View File

@@ -0,0 +1,38 @@
---
title: String Strip Method
localeTitle: 字符串条方法
---
## 字符串条方法
在Python `lstrip()` `rstrip()``strip()`从字符串中剥离字符有三个选项。
每个都将返回字符串的副本,其中包含从开头,结尾或开头和结尾删除的字符。如果没有给出参数,则默认为剥离空白字符。
例:
```py
>>> string = ' Hello, World! '
>>> strip_beginning = string.lstrip()
>>> strip_beginning
'Hello, World! '
>>> strip_end = string.rstrip()
>>> strip_end
' Hello, World!'
>>> strip_both = string.strip()
>>> strip_both
'Hello, World!'
```
可选参数可以作为包含要删除的所有字符的字符串提供。
```py
>>> url = 'www.example.com/'
>>> url.strip('w./')
'example.com'
```
但是,请注意只有第一个`.`从字符串中剥离出来。这是因为`strip`函数仅剥离位于左侧或最右侧的参数字符。因为w出现在第一个之前`.`它们被剥离在一起,而'com'出现在右边的前面`.`剥离后`/`
#### 更多信息:
字符串方法[文档](https://docs.python.org/3/library/stdtypes.html#string-methods) 。