Table of Contents Introduction List Comprehension Nested List Comprehension Dictionary Comprehension Set Comprehension Introduction List comprehensions provide a concise way to create lists. It is typically used to create new lists where each element is the result of some operations applied to each member of another...

Table of Contents The while Loop The break Statement for Loop with else while Loop with else The continue Statement The while Loop The while loop in Python is used to iterate over a block of code as long as the test expression is True. We typically use the while loop when we don’t know the number of times to iterate...

Table of Contents Introduction The for Loop Some Useful Functions The range() Function The enumerate() Function The random.sample() Function The random.choices() Function The zip() Function Introduction We know that Python statements are executed sequentially. That is, the first statement in a program is executed...

Table of Contents Introduction The if... else Statement The if... elif... else Statement Nested if Statements Introduction In writing a program, we often need to execute some statements only if certain condition(s) hold. The Python compound statement if, which uses if, elif, and else clauses, allows us to conditionally...