programming

Python Tree Data Structure

Learn tree data structure in Python with simple examples. Understand nodes, root, children, binary trees, binary search trees, DFS, BFS, inorder, preorder, and postorder traversal.

Deepak Prasad14 min read
programming

Sort Dictionary by Value in Python

Learn how to sort a dictionary by value in Python using sorted(), lambda, itemgetter(), reverse=True, and custom sorting. See examples for ascending order, descending order, duplicate values, and nested dictionaries.

Deepak Prasad7 min read
programming

Python Sort List

Learn how to sort a list in Python using list.sort() and sorted(). See examples for ascending order, descending order, strings, numbers, custom key functions, list of lists, tuples, dictionaries, None values, and common …

Bashir Alam7 min read
programming

Python Split String

Learn how to split a string in Python using str.split(). See examples for splitting by whitespace, comma, newline, multiple spaces, maxsplit, rsplit(), splitlines(), and regex delimiters.

Deepak Prasad6 min read
programming

Python startswith()

Learn how Python startswith() works with simple examples. Check if a string starts with a prefix, use start and end positions, match multiple prefixes with a tuple, and perform case-insensitive startswith checks.

Bashir Alam5 min read
programming

Python Set

Learn Python sets with simple examples. See how to create a set, add and remove items, check membership, remove duplicates, and use union, intersection, difference, symmetric difference, issubset, issuperset, and …

Deepak Prasad7 min read
programming

Python Static Method

Learn what a static method is in Python and how to use @staticmethod. See examples, static method vs class method vs instance method, when to use static methods, and common mistakes.

Bashir Alam7 min read
programming

Append String in Python

Learn how to append to a string in Python using +, +=, f-strings, format(), and join(). Understand why Python strings have no append() method and when to use each approach.

Deepak Prasad7 min read
programming

Check if String Contains Substring in Python

Learn how to check if a string contains a substring in Python using the in operator, find(), index(), count(), and regex. See case-sensitive, case-insensitive, multiple substring, whole-word, and pattern matching …

Deepak Prasad7 min read
programming

Python String Format

Learn Python string formatting using f-strings, str.format(), and percent formatting. See examples for variables, numbers, decimal precision, padding, alignment, percentages, dates, and %d meaning in Python.

Deepak Prasad6 min read
programming

Replace String in File Using Python

Learn how to replace text in a file using Python. See examples for replacing a string in the same file, writing to a new file, handling large files, using fileinput with backup, and regex replacement with re.sub().

Deepak Prasad5 min read
programming

Python Tuple

Learn what a tuple is in Python with simple examples. See how to create tuples, access items, use indexing and slicing, unpack tuples, compare tuples with lists, and use tuple methods.

Deepak Prasad9 min read
programming

Check Type in Python

Learn how to check the type of a variable in Python using type() and isinstance(). See when to use each method, how to check multiple types, and how type hints differ from runtime type checking.

Deepak Prasad9 min read
programming

Python yield Keyword

Learn what yield means in Python and how it creates generator functions. Understand yield vs return, next(), for loops, generator expressions, yield from, and common mistakes with simple examples.

Deepak Prasad7 min read
programming

Python writelines() Method

Learn Python writelines() method with examples. Write a list of strings to a file, add newline characters, append lines, compare write() vs writelines(), and avoid common mistakes.

Bashir Alam5 min read
programming

Python Write to File

Learn how to write to a file in Python using with open(). Create a new file, overwrite an existing file, append data, write multiple lines, and avoid common file mode mistakes.

Deepak Prasad6 min read
programming

Python While Loop with Multiple Conditions

Learn how to use multiple conditions in a Python while loop using and, or, not, parentheses, and two-condition examples. Understand when the loop stops and how to avoid infinite loops.

Deepak Prasad6 min read
programming

Python continue Statement

Learn how the Python continue statement works in for loops, while loops, if conditions, and nested loops, with examples, flowchart, break vs continue, and common mistakes.

Deepak Prasad7 min read
programming

Python pass Statement

Learn what the pass statement does in Python, when to use it in functions, classes, if blocks, loops, and exception handling, and how pass differs from continue, break, and return.

Deepak Prasad8 min read
programming

Python Optional Arguments

Learn how optional arguments work in Python functions, including default values, optional parameters, keyword arguments, *args, **kwargs, None defaults, and common mistakes.

Bashir Alam7 min read
programming

Python Constructor: __init__ Method Explained

Learn Python constructors using the __init__ method with examples for self, parameters, default values, validation, copying mutable arguments, object creation, inheritance, dataclasses, __new__, and common constructor …

Bashir Alam11 min read
programming

Python Operators

Learn Python operators with simple explanations, including arithmetic, comparison, assignment, compound assignment, logical, bitwise, membership, identity, and operator precedence.

Bashir Alam7 min read
programming

Python Numbers

Learn Python numeric types including integers, floating-point numbers, and complex numbers. Understand int vs float, type conversion, numeric literals, precision, and when to use each number type.

Deepak Prasad7 min read
programming

Python None Keyword

Learn what None means in Python, how NoneType works, how to check if a value is None, and when to use None for missing values, function returns, and default arguments.

Bashir Alam8 min read
programming

Python next() Function

Learn how Python next() works with iterators, default values, StopIteration, generators, first-item lookup, and first matching item patterns.

Deepak Prasad7 min read
programming

Python Create Directory Recursively

Learn how to create directories recursively in Python using pathlib Path.mkdir(parents=True, exist_ok=True) and os.makedirs(), including create-if-not-exists examples and common errors.

Deepak Prasad6 min read
programming

Python Multiline Comments

Learn how to write multiline comments in Python using multiple # comments. Understand why triple-quoted strings are not true comments, how docstrings differ from comments, and how to comment multiple lines in VS Code, …

Bashir Alam6 min read
programming

Python Matplotlib pyplot

Learn Python Matplotlib pyplot with simple plot examples. Create line plots, scatter plots, bar charts, and make beautiful plots using labels, colors, markers, legends, grids, styles, and savefig().

Deepak Prasad9 min read
programming

Python Custom Exceptions

Learn how to create custom exceptions in Python by subclassing Exception, raise custom exceptions with messages, catch them, add attributes, chain exceptions, and follow best practices.

Deepak Prasad8 min read
programming

Python List vs Tuple vs Set vs Dictionary

Compare Python list, tuple, set, and dictionary with examples. Learn the differences in order, mutability, duplicates, indexing, syntax, use cases, and when to use each data type.

Deepak Prasad9 min read