python - 如何从像列表这样的整数访问元素?
问题描述
我尝试运行代码:
for c in range(10, 21):
print(c)
print([c[1]])
我得到错误: TypeError: 'int' object is not callable 为什么?如何从整数中选择特定元素?
解决方案
result = [i for i in range(10,21)]
for c in result:
print(c)
print(result[1])
#你正在尝试的在 python 中是非法的。Int 'int' 对象不可订阅。#只有列表或元组、集合、字符串...是可下标的。
推荐阅读
- rabbitmq - 在 rsyslog 中找不到 Rabbitmq 模块
- jahia - 跟踪个性化版本视图 jExperience - Jahia Marketing Factory
- linux - 生成随机字符串,其中它必须在 shell 脚本中具有特殊字符
- xcode - 如何在特定版本上测试 MacOS 应用程序?
- node.js - npm install 现在总是抛出 errno EACCES 错误
- javascript - 如何成功调用通过弹出窗口请求登录的 URL?
- c# - 可以将 WCF 和 Web API 放在同一个解决方案中,在 c# 中共享同一个服务层吗?
- postgresql - 在 pg_dump postgresql 之后没有找到任何关系
- kubernetes - 为什么无法访问 css 和 png?
- android - Flutter 混淆 android appbundle