Files
ailearning/docs/da/147.md
2020-10-19 21:08:55 +08:00

132 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# string 模块:字符串处理
In [1]:
```py
import string
```
标点符号:
In [2]:
```py
string.punctuation
```
Out[2]:
```py
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
```
字母表:
In [3]:
```py
print string.letters
print string.ascii_letters
```
```py
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
```
小写和大写:
In [4]:
```py
print string.ascii_lowercase
print string.lowercase
print string.ascii_uppercase
print string.uppercase
```
```py
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
```
In [5]:
```py
print string.lower
```
```py
<function lower at 0x7efda4f2ae60>
```
数字:
In [6]:
```py
string.digits
```
Out[6]:
```py
'0123456789'
```
16 进制数字:
In [7]:
```py
string.hexdigits
```
Out[7]:
```py
'0123456789abcdefABCDEF'
```
每个单词的首字符大写:
In [8]:
```py
string.capwords("this is a big world")
```
Out[8]:
```py
'This Is A Big World'
```
将指定的单词放到中央:
In [9]:
```py
string.center("test", 20)
```
Out[9]:
```py
' test '
```