Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are these two python statements the same?

I have these two statements

return self.getData() if self.getData() else ''

and

return self.getData() or ''

I want to know are they same or there is any difference

like image 233
user3214546 Avatar asked Jun 09 '15 01:06

user3214546


1 Answers

I would say No because if self.getData() changes something during its operation, then the first statement has the possibility of returning a different result since it will make a 2nd call to it.

like image 109
mike.k Avatar answered Sep 18 '22 23:09

mike.k