如何制作循环输出的所有实体的单个列表

How to make a single list of all the entities of an output of a loop

下面是 returns 打印出 8 个数字的代码:

for i in range(A,A+30):
        for j in range(6,7):
            if "X" in str(sh1.cell(i,j).value):
                print(i)

命令行输出:

44
55
57
61
65
69
71
72

如何将这些实体按顺序存储在一个列表中,如下所示:

["44", "55", "57", "61", "65", "69", "71", "72"]

我想你想创建一个新的 list 并向其中添加项目:

values = []
for i in range(A,A+30):
    for j in range(6,7):
        if "X" in str(sh1.cell(i,j).value):
            print(i)
            values.append(str(i))

值 == ["44", "55", "57", "61", "65", "69", "71", "72"]

熟悉 lists(和其他基本 python 数据结构)会非常方便:https://docs.python.org/3/tutorial/datastructures.html#more-on-lists