且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TypeError:在for循环中创建类实例时,无法将“int”对象隐式转换为str

更新时间:2022-10-24 19:09:37

Turn the integer to a string explicitly then:

 players["player_" + str(x)] = Player(input("Name"), input("Starting Wealth"), x)

or use string formatting:

 players["player_{}".format(x)] = Player(input("Name"), input("Starting Wealth"), x)

You cannot just concatenate a string (player_) and an integer (the number between 0 and Player_count) referenced by x.

相关阅读

技术问答最新文章