Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call method on multiple instances in Python

Tags:

python

Is there something like this:

a,b,c = a,b,c.method()

?

It's just an example, I want to know the shortest way to do this

like image 580
user2733016 Avatar asked Oct 20 '25 09:10

user2733016


1 Answers

Not exactly that short, but if I understand you correct, this will work:

a, b, c = (x.method() for x in (a, b, c))

(Note, that if a, b or c are referring to the same object, the method will be called few times).

like image 125
bereal Avatar answered Oct 22 '25 00:10

bereal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!