gpt4 book ai didi

python将数字添加到字符串

转载 作者:太空狗 更新时间:2023-10-30 00:21:59 25 4
gpt4 key购买 nike

<分区>

尝试在字符串(网站 url) 的末尾添加一个 int 计数:

代码:

  count = 0
while count < 20:
Url = "http://www.ihiphopmusic.com/music/page/"
Url = (Url) + (count)
#Url = Url.append(count)
print Url

我要:

http://www.ihiphopmusic.com/music/page/2
http://www.ihiphopmusic.com/music/page/3
http://www.ihiphopmusic.com/music/page/4
http://www.ihiphopmusic.com/music/page/5

结果:

Traceback (most recent call last):
File "grub.py", line 7, in <module>
Url = Url + (count)
TypeError: cannot concatenate 'str' and 'int' objects

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com