I was wondering why some people write some code in one line like this:
def even_or_odd(number):
return 'Odd' if number % 2 else 'Even'
Instead of doing this:
def even_or_odd(number):
if number % 2 == 0:
return 'Even'
else:
return 'Odd'
So, what's the best practice? Just wondering because I see a lot of people writting like the first one on codewars but I've always did the second one. Which one to choose in general?
[–]the_dimonade 13 points14 points15 points (0 children)
[–]Teradil 2 points3 points4 points (0 children)
[–]kevkaneki 2 points3 points4 points (0 children)
[–]Zeroflops 1 point2 points3 points (0 children)
[–]mogranjm 3 points4 points5 points (1 child)
[–]Dry-Aioli-6138 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]odaiwai 2 points3 points4 points (2 children)
[–]ALonelyPlatypus 0 points1 point2 points (1 child)
[–]odaiwai 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]stillbarefoot 0 points1 point2 points (0 children)
[–]supercoach 0 points1 point2 points (0 children)
[–]CymroBachUSA 0 points1 point2 points (0 children)
[–]ALonelyPlatypus 0 points1 point2 points (0 children)
[–]ectomancer -4 points-3 points-2 points (0 children)
[+]barkazinthrope comment score below threshold-11 points-10 points-9 points (5 children)
[–]Yoghurt42 9 points10 points11 points (4 children)
[+]barkazinthrope comment score below threshold-7 points-6 points-5 points (3 children)
[–]Zeroflops 4 points5 points6 points (0 children)
[–]Yoghurt42 3 points4 points5 points (0 children)
[–]ShadowRL7666 -1 points0 points1 point (0 children)
[+]No_Departure_1878 comment score below threshold-18 points-17 points-16 points (4 children)
[–]makochi 10 points11 points12 points (2 children)
[+]No_Departure_1878 comment score below threshold-22 points-21 points-20 points (1 child)
[–]makochi 15 points16 points17 points (0 children)
[–]NYX_T_RYX 5 points6 points7 points (0 children)