b: a = b" in python? Can you shorten the following example? if file_size_download > file_size: file_size_...">

Is there a shorter way to write "if a> b: a = b" in python?

Can you shorten the following example?

if file_size_download > file_size: file_size_download = file_size

It looks pretty awkward for me.

+4
source share
2 answers
 a = min(a, b) 

It is short and concise.

+20
source

As a more general answer:

 a = b if a < b else a 

The previous answer works fine in this particular case, but it can be useful in cases where it is not just a comparison < .

0
source

Source: https://habr.com/ru/post/1345341/


All Articles