Python Tips and Tricks

Python tips and tricks to help you better understand Python and get the most out of the language.

The Python while-else Clause

The Python while-else clause is an additional, optional syntax Python's while loop supports, similar to the else clause in the for loop. It enables you to execute a code block after the loop has finished normally, that is, after the while loop's condition has become false. Abnormal, premature termination, due to reasons such as a break or return statement, skips that code.

Python Set Constructor Insights

The Python set constructor, set(), is a function that crates a Python set – a collection data structure that holds unique unordered elements. The set constructor can create a set out of various iterable data types, such as lists, tuples…