如何在Python中将变量值用作变量名的一部分?

我想知道是否有一种方法可以将变量值作为python中另一个变量名的一部分。我的代码在这里,但我认为应该有一种方法使其变得更整洁:

if self.player.dir == 'UP':
                    self.player.image = self.player.image_up[0]
                if self.player.dir == 'DOWN':
                    self.player.image = self.player.image_down[0]
                if self.player.dir == 'LEFT':
                    self.player.image = self.player.image_left[0]
                if self.player.dir == 'RIGHT':
                    self.player.image = self.player.image_right[0]

I was thinking if we could have the value of dir as part of the self.player.image_(dir)[0]. I am not sure how I would do this though. It would look something like this I think:

self.player.image = self.player.image_(dir)[0]

谢谢。

评论