元组索引超出范围是什么意思?

use*_*981 0 python printing format

任何人都可以阐明为什么:

print('{0} complete (down: {1} kb/s up: {2} kb/s {3} peers: {4} {5}'.format('state.progress * 100', 'state.download_rate / 1000', 'state.upload_rate / 1000', 'state.num_peers', 'state_str[state.state]'))
Run Code Online (Sandbox Code Playgroud)

结果元组索引超出范围?

Arc*_*676 5

您没有“第五”(或索引5)元素,因为第一个元素的索引为0。

因此,必须具有6个元素才能使用索引5。

print('{0} complete (down: {1} kb/s up: {2} kb/s {3} peers: {4} {5}'.format('state.progress * 100', 'state.download_rate / 1000', 'state.upload_rate / 1000', 'state.num_peers', 'state_str[state.state]'))
Run Code Online (Sandbox Code Playgroud)

在这里,您的元素是:

0: 'state.progress * 100'
1: 'state.download_rate / 1000'
2: 'state.upload_rate / 1000'
3: 'state.num_peers'
4: 'state_str[state.state]'
5: nil
Run Code Online (Sandbox Code Playgroud)