张姐卖炸串 2022-05-16 09:32 采纳率: 100%
浏览 153
已结题

python 使用 split()、strip()、replace() 等函数进行处理大小写

有以下字符串:

    strZen  = '''   siMPle iS bEtter thAn c0MplEx.
             eRr0rs Sh0uLd nEveR PasS sIlently.   
             n0w iS beTtER THan NeveR.  '''

    可以看出,字符串的内容并不工整,并且字母 'o',被错误的写成了数字字符 '0';

    使用 split()、strip()、replace() 等函数进行处理,并输出为如下格式:

    Simple is better than complex.
    Errors should never pass silently.
    Now is better than never.
  • 写回答

3条回答 默认 最新

  • 不会长胖的斜杠 后端领域新星创作者 2022-05-16 09:47
    关注
    strZen  = '''   siMPle iS bEtter thAn c0MplEx.
                 eRr0rs Sh0uLd nEveR PasS sIlently.   
                 n0w iS beTtER THan NeveR.  '''
    strZen = strZen.strip().replace('0','o').split(".")
    for i in strZen:
        print(i.title(),end='')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 5月28日
  • 已采纳回答 5月20日
  • 创建了问题 5月16日