类型错误:'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]类型错误:"bool"对象没有属性">getitem">

任何帮助都将是有益的

.slower((方法返回一个bool,表示如果给定的字符串只有小写,则需要.lower((

.slower返回True或False,.lower((返回实际字符串:

>>> 'a'.islower()
True
>>> 'a'.lower()
'a'

[::-1]返回一个字符串。当您尝试比较字符串和布尔值时,会出现错误。

最新更新