Append to Python dictionary from method

前端 未结 3 563
终归单人心
终归单人心 2021-01-27 12:27

I have this dictionary called biography

self.biography = {\'Name\' : \'\', \'Age\' : 0, \'Nationality\' : \'\', \'Position\' : 0, \'Footed\' : \'\'}
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-27 13:09

    def create_player(self):
        for key in self.biography.keys():
            val = input('Player {}: '.format(key.lower()))
            self.biography[key] = int(val) if val.strip().isdigit() else val
    

提交回复
热议问题