Python13 期字符串大考核!!!

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

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

Python13期 前来报道!!!

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

    image.png

  • 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))
    
  • qiuqiu

    image.png

  • ping

    image.png

  • 715173855

    image.png

  • ruo0

    image.png

  • ruo0

    image.png

  • zhy754709516

    image.png

  • Juan_ying

    image.png

  • Juan_ying

    image.png

  • zhaow306

    image.png

  • Sunny

    image.png

    image.png

  • marin

    image.png

  • marin

    image.png

  • 18923722612

    image.png

    运行结果如图:image.png

  • f_guiling

    image.png

  • jiangjiang

    image.png

  • liyanhe

    w='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    print(w.swapcase())
    print(w.replace('A','Z',2))

  • aniu

    image.png

  • xiaomomo

    image.png

  • liyanhe

    w='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    w1=w.swapcase()
    print('大小写转换后的字符串:',w1)
    new_w=''
    for i in w:
    if i.islower():
    i = chr(219-ord(i))
    new_w +=i
    elif i.isupper():
    i = chr(155 - ord(i))
    new_w +=i
    print('镜像字符串是:',new_w)

  • monica

    image.png
    image.png

  • chenfeng1987

    image.png

  • song_s

    image.png

  • S20145627

    不太了解镜像的意思,个人认为是倒着输出来的样子吧
    a=”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”;
    for(i=len(a);i>=len(a);i-1)
    {
    print(i);
    }

    a=”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”;
    print(a.upper());

    a=”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”;
    print(a.lower());

  • anhao1007

    image.png

  • AQ13

    image.png

  • JYC

    image.png

  • JYC

    image.png

  • 1923

    image.png

请输入回帖内容 ...