Skip to main content

23. Python Lists

Create List

Output
Explanation Lists store ordered, mutable collections.

Access List Items

Output
Explanation Access items using indexes.

Change List Items

Output
Explanation Modify items using indexes.

Add List Items

Output
Explanation append() adds an item to the end.

Remove List Items

Output
Explanation remove() deletes a specified item.

Loop Lists

Output
Explanation Iterate through each item in the list.

List Comprehension

Output
Explanation Create lists using a concise syntax.

Sort Lists

Output
Explanation Sort items in ascending order.

Copy Lists

Output
Explanation Create a separate copy of a list.

Join Lists

Output
Explanation Combine two lists.

Common List Methods


24. Python Tuples

24.1 Create Tuple

Output

Explanation: A tuple stores multiple ordered items.

24.2 Tuple Length

Output

Explanation: len() returns the number of items in a tuple.

24.3 Create Tuple With One Item

Output

Explanation: A single-item tuple must end with a comma.

24.4 Tuple Data Types

Output

Explanation: Tuples can store different data types.

24.5 Access Tuple Items

Output

Explanation: Access tuple items using indexes.

24.6 Negative Indexing

Output

Explanation: Negative indexes start from the end.

24.7 Range of Indexes

Output

Explanation: Slice returns a portion of the tuple.

24.8 Check if Item Exists

Output

Explanation: in checks whether an item exists.

24.9 Change Tuple Items

Output

Explanation: Convert to a list to modify tuple items.

24.10 Add Items

Output

Explanation: Tuples are immutable, so create a new tuple.

24.11 Remove Items

Output

Explanation: Convert to a list to remove items.

24.12 Unpack Tuples

Output

Explanation: Assign tuple values to separate variables.

24.13 Using Asterisk (*)

Output

Explanation: * collects remaining values into a list.

24.14 Loop Through Tuple

Output

Explanation: Loop through tuple items using for.

24.15 Join Tuples

Output

Explanation: + joins two tuples.

24.16 Multiply Tuples

Output

Explanation: * repeats tuple elements.

24.17 Tuple Methods

count()

Output
Explanation: Counts occurrences of an item.

index()

Output
Explanation: Returns the index of the first occurrence.

25. Python Sets

25.1 Create Set

Output

Explanation: Sets store unordered unique items.

25.2 Set Length

Output

Explanation: Returns the number of items.

25.3 Duplicate Values

Output

Explanation: Duplicate values are removed automatically.

25.4 Access Set Items

Output

Explanation: Sets do not support indexing.

25.5 Check Item Exists

Output

Explanation: in checks item existence.

25.6 Add Items

Output

Explanation: add() inserts one item.

25.7 Add Multiple Items

Output

Explanation: update() adds multiple items.

25.8 Remove Item

Output

Explanation: remove() deletes an item.

25.9 discard()

Output

Explanation: discard() doesn’t raise an error if the item doesn’t exist.

25.10 pop()

Output

Explanation: Removes a random item.

25.11 clear()

Output

Explanation: Removes all items.

25.12 Loop Set

Output

Explanation: Iterate through every item.

25.13 Join Sets (Union)

Output

Explanation: Combines all unique elements.

25.14 Intersection

Output

Explanation: Returns common items.

25.15 Difference

Output

Explanation: Returns items only in the first set.

Common Set Methods


26. Python Dictionaries

26.1 Create Dictionary

Output

Explanation: Dictionaries store data as key-value pairs.

26.2 Dictionary Length

Output

Explanation: Returns the number of key-value pairs.

26.3 Access Items

Output

Explanation: Access values using keys.

26.4 get()

Output

Explanation: get() safely returns a value.

26.5 keys()

Output

Explanation: Returns all keys.

26.6 values()

Output

Explanation: Returns all values.

26.7 items()

Output

Explanation: Returns key-value pairs.

26.8 Change Items

Output

Explanation: Change a value using its key.

26.9 update()

Output

Explanation: Adds or updates key-value pairs.

26.10 Add Items

Output

Explanation: Assign a new key to add an item.

26.11 Remove Items

pop()

Output
Explanation: Removes a specified key.

popitem()

Output

Explanation: Removes the last inserted item.

del

Output

Explanation: Deletes a key-value pair.

clear()

Output

Explanation: Removes all items.

26.12 Loop Dictionaries

Output

Explanation: Iterate through keys and values.

26.13 Copy Dictionary

Output

Explanation: Creates a separate copy of the dictionary.

26.14 Nested Dictionaries

Output

Explanation: A dictionary can contain other dictionaries.

Common Dictionary Methods