[Tutor] use of assignment expression

Manprit Singh manpritsinghece at gmail.com
Sun Aug 16 09:55:33 EDT 2020


Dear sir ,
i need  a comment on the use of assignment expression in the below given
example :

# Program to find smallest n digit number divisible by a number x
n = 5
x = 83
if (no := (10**(n-1) % x)) == 0:
    print(10**(n-1))
else:
    print((mx := (10**(n-1) + x)) - (mx % x))

The answer is 10043, which is the right answer . Just need to know if the
way of using the assignment expression (2 times in the above example is
efficient or not.),

What i feel is the usage of assignment expressions is reducing the
readability of the code written above  . Need your guidance.

Regards
Manprit


More information about the Tutor mailing list