A special place use of the "if" keyword in Python is within list comprehensions. This so-called "guard" serves to select what elements of the original list or other iterable will be added to the comprehension; it works as a kind of filter. This form of the "if" statement is never followed by an "else". For more information, see the notebooks below (notebooks will open on Google Colab - no installation required)
Embedded video, part of the following courses:
Computer Programming at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/4umjbjvp
Coding for Scientists at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/539p4b5f
Watch video The "if" keyword in list comprehensions (vs the normal if - else) online without registration, duration hours minute second in high quality. This video was added by user PatchyPython 19 September 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 92 once and liked it 0 people.