首页 > 解决方案 > TypeError:'bool' 对象没有回文的属性 '__getitem__'

问题描述

我正在尝试在不使用反向函数的情况下创建回文:以下是我的代码

    import sys
    print (sys.argv)
    arg=len(sys.argv)


# check to determine if there is more than one argument on the command line

    if len(sys.argv) !=2:
       print("Specify 1 argument")

    else:
       statement=sys.argv[1]

#remove any space in the statement
    list=[]

for info in statement:
    if info == " ":
        list.append(info)
# create one string variable
    string="".join(list)

# make string lower case 
    string_lower=string.islower()

# reversing list 
    reverse_lower = string_lower[::-1]

# compare the orginal list to the reverse list 
    if (string_lower == reverse_lower):
       print("It's a palindrome!")
    else:
       print("It's not a palindrome!")

我收到一条错误消息:

reverse_lower=string_lower[::-1] TypeError: 'bool' 对象没有属性 ' getitem '

任何帮助都是有益的

标签: python

解决方案


.islower() 方法返回一个布尔值,表示如果给定的字符串只是小写,你想要 .lower()


推荐阅读