## List Comprehension

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...

## While Loops

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...

## For Loops

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...

## If Statements

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...

## Sets

Table of Contents Introduction Defining a Set List vs Tuple vs Dictionary vs Set Modifying a Set Mathematical Set Operations Introduction A set is an unordered collection of unique elements which are unindexed. Sets are mutable which means they can be modified in-place without creating a new object. However, set items...

## Dictionaries

Table of Contents Introduction Defining a Dictionary Modifying a Dictionary List vs Tuple vs Dictionary Dictionary Methods Introduction Just like lists, Python dictionaries (dict) are another mutable data structure. However, in contrast to lists and tuples, dictionaries are unordered. That is, the order of the elements...

## Tuples

Table of Contents Introduction Basic Tuple Operations Tuple Indexing and Slicing Tuple Methods Introduction Tuples are similar to lists with the difference that they are immutable. Once created, their elements cannot be changed unless a new tuple object is created. Tuples are the obvious choice for a collection of...

## Functions

Table of Contents Introduction Defining Functions Calling Functions The sorted() Function Lambda Functions Namespace and Scope (optional) Introduction A function is a block of code that performs a specific task and only runs when it is called. Functions help break our program into smaller modular chunks. As our program...

## Lists

Table of Contents Introduction Basic List Operations List Indexing and Slicing Mutable vs Immutable Objects List Methods Introduction The list is one of the most important data structures available in Python used to store multiple items in a single variable. It is written as a sequence of comma-separated values...

## Data Types

Table of Contents Data Types Integers and Floating-point Numbers Strings String Methods Mixing Strings and Variables Indexing and Slicing Strings Indexing Strings Slicing Strings Booleans Comparison Operators Logical Operators Data Types Variables can store data of different types, and different data types serve...