这是一个创建于 1996 天前的主题,其中的信息可能已经有所发展或是发生改变。
import re
states = [' Alabama ', 'Georgia!', 'Georgia', 'georgia', 'FlOrIda',
'south carolina##', 'West virginia?']
def clean_strings(strings):
result = []
for value in strings:
value = value.strip()
value = re.sub('[!#?]', '', value)
value = value.title()
result.append(value)
return result
print(clean_strings(states))
为了使 states 中的数据整齐,所以需要清洗数据。
其中 value = value.strip()这行代码似乎可有可无,因为即使将其注释掉,输出结果依然没有变化。
.strip()方法的作用是什么呢?
|
|
1
qinghon 2019-04-24 00:04:55 +08:00 via Android
python strip Google 请
|
|
|
2
banixc 2019-04-24 00:05:40 +08:00
|
|
|
3
smallpython 2019-04-24 11:48:28 +08:00
搜一下 strip ()这个函数有什么作用就可以了
|