forked from ls1248659692/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.py
More file actions
51 lines (39 loc) · 846 Bytes
/
Copy pathstring.py
File metadata and controls
51 lines (39 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.
import string
def string_operations():
s = 'abcab'
# join
','.join(s)
# split
s.split(',')
# replace
s.replace()
# index & find, index return -1 if not found
s.index('a')
s.find('a')
s.rfind('a')
# count
s.count('a')
# start & end with
s.startswith('a')
s.endswith('b')
# translate
intab = "aeiou"
outtab = "12345"
trantab = str.maketrans(intab, outtab)
s.translate(trantab)
# strip
s.lstrip()
s.rstrip()
s.strip()
# just
s.ljust(10)
s.rjust(10)
s.center(10)
s.zfill(10)
# common string
string.punctuation
string.whitespace
string.ascii_lowercase
string.hexdigits
string.printable