What does “Type Error: Can't convert 'int' to str implicitly” mean?

前端 未结 2 1686
陌清茗
陌清茗 2021-01-27 12:21
def display_positive_indices(strlen):
    print()
    print(\' \', end=\'\')
    for i in range(strlen + 1):
        print(i, end=\'\')
        if i != strlen:
                  


        
2条回答
  •  遇见更好的自我
    2021-01-27 13:03

    Since you require an integer you can coerce it to the type you would like, and if it cannot be converted you will get a TypeError or ValueError:

    ...
    strlen = int(strlen)
    for i in range(strlen + 1):
        ...
    

提交回复
热议问题