Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向列表中添加数字_Python_Web Scraping - Fatal编程技术网

Python 向列表中添加数字

Python 向列表中添加数字,python,web-scraping,Python,Web Scraping,我正在建造一个用于教育目的的激流刮板。我想学习网页抓取,所以我认为这将是一个很好的方式这样做。无论如何,我试图打印出一个编号的torrents列表,但当我尝试执行for循环,向列表中的torrents添加编号时,我无法使用相同的变量,因为它们被转换为字符串。我怎样才能解决这个问题?这是我正在使用的代码 for torrent in torrents: print (str (torrent + 1)) 你能解释一下打印出来的数字是什么意思吗?那么,你是指列表中的索引吗 for inde

我正在建造一个用于教育目的的激流刮板。我想学习网页抓取,所以我认为这将是一个很好的方式这样做。无论如何,我试图打印出一个编号的torrents列表,但当我尝试执行for循环,向列表中的torrents添加编号时,我无法使用相同的变量,因为它们被转换为字符串。我怎样才能解决这个问题?这是我正在使用的代码

for torrent in torrents:
    print (str (torrent + 1))

你能解释一下打印出来的数字是什么意思吗?那么,你是指列表中的索引吗

for index, torrent in enumerate(torrents):
  print(str(index) + ', ' + str(torrent))
我会给你

0, torrent0String
1, torrent1String
...

是的,我想把名单编成这样的数字1字符串2字符串3字符串等