怎么从字符串s1中取出字母,按顺序存储到s2中。例,s1中输入“ 2aA3bB5”,在s2中显示“aAbB”。
4条回答 默认 最新
- CSDN专家-天际的海浪 2021-03-30 16:55关注
# 用正则表达式把不是字母的字符都删除。 import re s1 = "2aA3bB5" s2 = re.sub(r'[^A-Za-z]','',s1) print(s2)
# 用for循环的方法。 s1 = "2aA3bB5" s2 = "" for c in s1: if c.isalpha(): s2 += c print(s2)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用