Python13 期字符串大考核!!!

本贴最后更新于 1567 天前,其中的信息可能已经时移世异

请用自己目前所学实现字符串大写转小写,小写变大写,并且将字符串变为镜像字符串。例如:’A’变为’Z’,’b’变为’y
示范字符串:
”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”字符串大写变小写 小写变大写,然后最后变为镜像字符串。

Python13期 前来报道!!!

107 回帖
请输入回帖内容 ...
  • Limei

    s="sdSdsfdAdsdsdfsfdsdASDSDFDSFa"
    print(s.upper())
    print(s.lower())
    print(s.swapcase())

    print("替换前:",s)
    s_1=s.replace('s','h')
    s_2=s_1.replace('S','H')
    s_3=s_2.replace('f','u')
    s_4=s_3.replace('A','Z')
    s_5=s_4.replace('D','W')
    s_6=s_5.replace('F','U')
    s_7=s_6.replace('d','w')
    s_8=s_7.replace('a','z')
    print("替换后:",s_8)

  • 其他回帖
  • JUNE

    c='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    print(c.swapcase())
    new_c=''
    for i in c:
    if i.islower():
    i=chr(219-ord(i))
    new_c += i
    elif i.upper():
    i=chr(155-ord(i))
    new_c += i
    print(new_c)

    结果:
    SDsDSFDaDSDSDFSFDSDasdsdfdsfA
    hwHwhuwZwhwhwuhuwhwZHWHWUWHUz

  • zhouhuahua

    a='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    print (a.swapcase())
    #字符串大小写转换
    a='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    s = ''
    for i in a:
    if i.islower():
    i = chr(219 - ord(i))
    s += i
    elif i.isupper():
    i = chr(155 - ord(i))
    s += i
    print(s)
    #镜像字符串

  • nichen
    a = "sdSdsfdAdsdsdfsfdsdASDSDFDSFa"
    # 大小写互换
    new_a = a.swapcase()
    
    # 镜像字符串
    
    str_image = ""# 镜像后的字符串
    str_1 = "abcdefghijklmnopqrstuvwxyz"
    str_2 = str_1[::-1] # 小写字母对应镜像字符串
    
    for i in new_a:
        if i.islower():
            str_image += str_2[str_1.find(i)]
        else:
            str_image += str_2[str_1.find(i.lower())].upper()
    print("""大小写互换后:{}
    镜像字符串为:{}""".format(new_a,str_image))
    
  • 查看更多回帖