Questions
Python questions
Choose a question page, learn the concept, then test your understanding with a quiz.
How to Sort a List of Dictionaries by Key in Python
Learn how to sort a list of dictionaries by a key in Python using sorted() and list.sort() with clear examples and common mistakes.
How to Split a List Into Equal-Sized Chunks in Python
Learn how to split a Python list into equal-sized chunks with clear examples, step-by-step logic, common mistakes, and a mini project.
How to Upgrade All Python Packages with pip
Learn how to upgrade all installed Python packages with pip, why pip has no single built-in command, and safe ways to do it step by step.
How to Use Global Variables in Python Functions
Learn how global variables work in Python functions, when to use the global keyword, and how to avoid UnboundLocalError.
Iterating Over Dictionary Keys with a for Loop in Python
Learn how Python for loops iterate over dictionary keys, why `key` is just a variable name, and how dict iteration works in practice.
Python *args and **kwargs Explained in Function Parameters
Learn what *args and **kwargs mean in Python function parameters, how they work, when to use them, and common mistakes to avoid.
Python Argument Passing Explained: Pass by Reference vs Rebinding
Learn how Python argument passing works, why rebinding a parameter does not change the caller, and how to mutate objects correctly.
Python Current Working Directory vs Script Directory Explained
Learn how to get the current working directory and the running Python file's directory, with examples, differences, and common mistakes.
Python Function Decorators: How to Create and Chain Them Together
Learn how to write Python function decorators and stack them correctly to wrap return values like bold and italic HTML tags.
Python List append() vs extend(): What’s the Difference?
Learn the difference between Python list append() and extend() with clear examples, behavior comparisons, and common mistakes.
Python Mutable Default Arguments Explained: Why Defaults Are Evaluated Once
Learn why Python mutable default arguments are evaluated at function definition time, how bugs happen, and the safe pattern to use instead.
Python Static Variables and Methods: Class Variables, @classmethod, and @staticmethod
Learn how class variables and static methods work in Python, when to use them, and how they differ from instance variables and methods.
Python String Contains: How to Check for a Substring in Python
Learn how to check whether a Python string contains a substring using `in`, `find()`, and related techniques with examples.
Python String Slicing: How to Get a Substring in Python
Learn how to get substrings in Python using string slicing, including start, end, omitted indexes, and practical examples.
Select Rows by Column Values in Pandas DataFrames
Learn how to filter rows in a Pandas DataFrame by column values using boolean indexing, multiple conditions, and common patterns.
Understanding Python super() with __init__() Methods
Learn why Python super() is used, how it differs from Base.__init__(), and when to use each in inheritance.
What Are Metaclasses in Python? A Beginner-Friendly Guide
Learn what metaclasses are in Python, how they work, why they matter, and when to use them with simple examples.
What __init__.py Is For in Python Packages
Learn what __init__.py does in Python, why it exists in packages, and how it is used for imports, setup, and module organization.
What `if __name__ == "__main__":` Does in Python
Learn what `if __name__ == "__main__":` means in Python, why it matters, and how it controls code when files are run or imported.
What the yield Keyword Does in Python
Learn what Python's yield keyword does, how generators work, and what happens when generator functions are called and iterated.