python - 基数为 10 的 int() 的无效文字:'(1,2,3,4,5,6,7)'
问题描述
tuple1 = int(input())
list1 = list()
for i in tuple1:
if tuple1[i-1] % 2 == 0:
list1.append(tuple1[i-1])
tuple2 = tuple(list1)
print(tuple2)
我收到错误
基数为 10 的 int() 的无效文字:'(1,2,3,4,5,6,7)'
解决方案
您可以使用literal_eval
fromast
模块尝试将输入转换为 a tuple
,例如
from ast import literal_eval
s = '(1,2,3,4,5,6,7)' # your input...
t = literal_eval(s)
print(t, type(t))
# (1, 2, 3, 4, 5, 6, 7) <class 'tuple'>
推荐阅读
- python-3.x - Beautiful Soup 通过 id 找到 td 为什么这不起作用
- python - 无法使用子进程执行 sudo 命令
- sql-server - Snowflake SSRS ODBC error : No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command
- linux - Ubuntu 中的 GitHub 克隆问题
- flutter - Dart/Flutter 中的多态性
- validation - Kotlin 数据类强制值约束
- prestashop - 在 Prestashop 中编辑页脚链接的正确 .tpl 文件是什么
- angular - 如何根据环境而不是目标从 Angular 构建中添加或删除文件/代码?
- mongodb - 如何在聚合中的对象数组上使用 $map?
- oracle - sqlplus 格式输出