Single line if statement with a continue

Abdullah Nafees abdullahnafees23 at gmail.com
Sat Dec 17 14:22:42 EST 2022


Just wanted to say that a silent reader like me learnt more about PEP-8
solely from this thread than my mentor at work or any other course I have
taken earlier this year. Thank you so much.

On Sun, 18 Dec 2022, 00:16 Rob Cliffe via Python-list, <
python-list at python.org> wrote:

>
>
> On 15/12/2022 04:35, Chris Angelico wrote:
> > On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist at gmail.com>
> wrote:
> >> I occasionally run across something like:
> >>
> >> for idx, thing in enumerate(things):
> >>      if idx == 103:
> >>          continue
> >>      do_something_with(thing)
> >>
> >> It seems more succinct and cleaner to use:
> >>
> >> if idx == 103: continue.
> >>
> >>
> >> Nothing at all wrong with writing that on a single line. If you have
> >> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
> >>
> >> ChrisA
> I'm so glad that Chris and others say this.  It (i.e. if plus
> break/continue/return on a single line) is something I have quite often
> done in my own code, albeit with a feeling of guilt that I was breaking
> a Python taboo.  Now I will do it with a clear conscience. 😁
> Best wishes
> Rob Cliffe
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list