打印列表中整数的一部分

Printing a part of an integer in a list

要打印字典键下的整个整数,以下代码有效:

print(config[('r' + str(config['lines']))])

但是,如果我只想打印第一个数字并添加 [1]

print(config[('r' + str(config['lines']))][1])

我收到错误 TypeError:'int' 对象不可订阅 。如何只打印整数的第一个数字?

将数字转换为字符串,以便您可以对其下标。

print(str(config[('r' + str(config['lines']))])[0])

索引从 0 开始,因此您需要使用 [0] 来获取第一个数字。