When your function ends in an "else" block with a "return" statement in it, should you remove that "else"?
Also see related pylint rule R1705 (no-else-return) or ruff rule RET505 (superfluous-else-return), which I don't recommend always following.
And note that the example in the code could use a ternary operator, though it might be a long one!: • Python's ternary operator
Article at https://pym.dev/unnecessary-else-stat...
More #Python screencasts at https://pym.dev/screencasts/
00:00 A function where both if and else return
00:20 Is that else statement unnecessary?
00:30 Sometimes else improves readability
01:12 When should you remove an else statement?
01:58 Considering readability with if-else statements
Смотрите видео Unnecessary else statements онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Python Morsels 22 Март 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 580 раз и оно понравилось 37 людям.