python - 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 '
任何帮助都是有益的
解决方案
.islower() 方法返回一个布尔值,表示如果给定的字符串只是小写,你想要 .lower()
推荐阅读
- c++11 - std::memory_order_* 在 x86(-64) 上的效果/实现
- javascript - 量角器,'for' 循环不会对所有索引执行操作
- python - 在 Python 3.5 中使用密码学进行解密
- html - SVG调整大小冲突
- scala - ParMap 的 Monoid 实例?
- bash - Bash:'echo'不输出在同一行上定义的变量
- c# - 并行性的异步函数混淆
- python - 使用 python 和 h5py 更新 hdf5 中的键值
- opencv - 检测到人时如何在opencv python中保存帧
- javascript - 使用 getJSON 显示 div 内的所有对象