小编jok*_*inx的帖子

python将数字添加到字符串

尝试将count int添加到字符串的末尾(网站URL):

码:

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

我想要:

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
Run Code Online (Sandbox Code Playgroud)

结果:

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

python

5
推荐指数
2
解决办法
5万
查看次数

索引范围错误

我一直收到错误'IndexError:list index out of range'

不知道我做错什么它适用于一对夫妇运行错误我唯一能想到的是我得到的名字太长了变量

        mylist = [x +'.mp3' for x in re.findall(r'file=(.*?).mp3',the_webpage)]
    #Remove Duplicates
    if mylist:
        mylist.sort()
        last = mylist[-1]
        for i in range(len(mylist)-3, -1, -1):
            if last == mylist[i]:
                del mylist[i]
            else:
                last = mylist[i]
    print " "
    #takes the quotes out of the string
    #ti = titl1[0]
    n1 = titl1[0]
    n2 = song1[0]

    #sg = song1
    sname = "".join(tuple(n1 + "-" + n2 + ".mp3"))

    print sname
    url = mylist[0]
Run Code Online (Sandbox Code Playgroud)

结果

Traceback (most recent call last): …
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
120
查看次数

标签 统计

python ×2