-
Notifications
You must be signed in to change notification settings - Fork 39
/
81-Chinese.py
52 lines (47 loc) · 1.06 KB
/
81-Chinese.py
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
52
c = [
'决',
'决决',
'决决决',
'决决决决',
'决决决决决',
'决决决决决决',
'决决决决决决决'
]
print('----正常字符串格式化:----')
for x in range(len(c)):
print('|%20s|' % c[x])
'''
执行结果:
----正常字符串格式化:----
| 决|
| 决决|
| 决决决|
| 决决决决|
| 决决决决决|
| 决决决决决决|
| 决决决决决决决|
'''
print()
print()
print()
def chinese(data):
count = 0
for s in data:
if ord(s) > 127:
count += 1
return count
print('----通过函数计算长度格式化:----')
for x in range(len(c)):
number = chinese(c[x])
newStr = '{0:{wd}}'.format(c[x],wd=20-number)
print('|%s|' % newStr)
'''
----通过函数计算长度格式化:----
|决 |
|决决 |
|决决决 |
|决决决决 |
|决决决决决 |
|决决决决决决 |
|决决决决决决决 |
'''