【问题标题】:Capital letters in Jython/JESJython/JES 中的大写字母
【发布时间】:2017-10-11 20:42:35
【问题描述】:

我目前正在编写一个 JES 程序,它根据是否将包含回文的字符串传递给它来返回 True 或 False。尽管该程序可以运行,但当出现大写字母或标点符号时它会失败。我怎样才能让它工作?

print(ThisPalindrome("racecar"))

>> True 

print(ThisPalindrome("Racecar"))

>> False

【问题讨论】:

    标签: python jython jes


    【解决方案1】:

    要解决大小写问题,您可以尝试在支票中使用str.lower() 方法。

    def ThisPalindrome(word):
        lowercase = word.lower()
        reversedOrder = reversed(lowercase)
        if lowercase == ''.join(reversedOrder):
            return True
        else:
            return False
    

    理论上,只要不破坏功能,该功能也应该与基本标点符号一起使用。 ' 等输入可能会导致其中断。

    【讨论】:

      【解决方案2】:

      toLowerCase() 方法返回转换为小写的调用字符串值。

      replace() 方法返回一个新字符串,其中模式的部分或全部匹配被替换替换。我们将使用我们之前创建的 RegExp 之一。

      split() 方法通过将字符串拆分为子字符串,将 String 对象拆分为字符串数组。

      reverse() 方法将数组反转。第一个数组元素成为最后一个,最后一个成为第一个。

      【讨论】:

        猜你喜欢
        • 2013-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多