Questions
Python questions
Choose a question page, learn the concept, then test your understanding with a quiz.
@staticmethod vs @classmethod in Python Explained
Learn the difference between @staticmethod and @classmethod in Python with clear examples, use cases, mistakes, and a mini project.
Call a Function by Name in a Python Module
Learn how to call a function by name in a Python module using strings, getattr, and safe patterns for dynamic function dispatch.
Catch Multiple Exceptions in One except Block in Python
Learn how to catch multiple exceptions in one Python except block using tuples, with examples, mistakes, and real-world usage.
Convert Bytes to String in Python 3
Learn how to convert bytes to str in Python 3 using decode(), text mode, and proper encodings with practical examples.
Create a Dictionary from Two Lists in Python
Learn how to combine separate lists of keys and values into a Python dictionary using zip() and dict() with clear examples.
Delete a Column from a Pandas DataFrame in Python
Learn why `del df['col']` works in Pandas but `del df.col` does not, and how attribute access differs from column access in Python.
Delete an Element from a Dictionary in Python
Learn how to remove items from a Python dictionary, including how to create a new dictionary without changing the original.
Does Python Have a Ternary Conditional Operator? Conditional Expressions in Python
Learn whether Python has a ternary operator, how conditional expressions work, and when to use them with clear Python examples.
Generate Random Integers Between 0 and 9 in Python
Learn how to generate random integers from 0 to 9 in Python using the random module, with examples, pitfalls, and practice.
Get a Filename Without Its Extension from a Path in Python
Learn how to extract a filename without its extension from a file path in Python using pathlib and os.path with clear examples.
How Python Slice Notation Works: A Beginner-Friendly Guide
Learn how Python slicing works with start, stop, and step. Understand a[x:y:z], a[:], and a[::2] with clear examples.
How to Access Environment Variables in Python
Learn how to read environment variables in Python using os.environ and os.getenv, with examples, pitfalls, and practical use cases.
How to Access the Index in a Python for Loop
Learn how to access the index in a Python for loop using enumerate(), with examples, pitfalls, and real-world use cases.
How to Add New Keys to a Python Dictionary
Learn how to add new keys to a Python dictionary, update values, avoid common mistakes, and use practical examples in real code.
How to Append to a File in Python Instead of Overwriting It
Learn how to append to a file in Python using append mode, avoid overwriting data, and understand file modes with clear examples.
How to Change Figure Size in Matplotlib (Python)
Learn how to change figure size in Matplotlib using figsize, set_size_inches, and rcParams with clear Python examples.
How to Check an Object’s Type in Python with type() and isinstance()
Learn the canonical way to check an object’s type in Python using isinstance() and type(), with examples, inheritance behavior, and pitfalls.
How to Check if a File Exists in Python Without Exceptions
Learn how to check whether a file exists in Python without try/except using os.path and pathlib with simple examples.
How to Check if a Key Exists in a Python Dictionary
Learn the best way to check whether a key exists in a Python dictionary, with examples, pitfalls, and real-world usage patterns.
How to Check if a List Is Empty in Python
Learn how to check if a list is empty in Python using idiomatic truthiness, len(), and common patterns with examples and mistakes.
Page 1 of 6 - 112 questions