Questions
Python questions
Choose a question page, learn the concept, then test your understanding with a quiz.
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 Comprehension with if/else: Conditional Expressions
Learn the correct Python list comprehension syntax for transforming values with an if/else conditional expression, with examples and pitfalls.
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 None: How to Represent a Null Value
Learn how Python represents null values with None, how to test it correctly using is, and where it appears in real Python code.
Python Relative Imports Explained: Fixing "attempted relative import with no known parent package"
Learn why Python relative imports fail, what packages are, and how to run modules correctly with -m to avoid import errors.
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 Formatting: %, str.format(), and f-Strings
Learn when to use Python percent formatting, str.format(), and f-strings, including formatting timing, performance, logging, and templates.
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.
Python Switch Statement Alternatives: Dictionary Dispatch, if/elif, and match
Learn Python alternatives to switch statements using dictionaries, if/elif chains, and structural pattern matching with practical examples.
Python Threading: Divide Tasks Across Multiple Threads
Learn Python threading with clear examples for dividing independent tasks, coordinating results, avoiding common errors, and choosing threads wisely.
Python Virtual Environments Explained: venv vs virtualenv vs pyenv vs pipenv
Learn the differences between Python tools like venv, virtualenv, pyenv, virtualenvwrapper, and pipenv with clear examples and use cases.
Python assert Statement: Purpose, Usage, and Examples
Learn what Python's assert statement does, how assertions detect programming errors, and when to use them with clear examples.
Python b String Prefix: Bytes Literals Explained
Learn what the Python b prefix means, how bytes differ from str, when to use byte literals, supported prefixes, and common pitfalls.
Python type() vs isinstance(): Exact Types and Subclasses
Learn the differences between Python type() and isinstance(), including exact type checks, subclass support, modern syntax, pitfalls, and examples.
Random String Generation with Uppercase Letters and Digits in JavaScript
Learn how to generate random strings of length N using digits and uppercase letters in JavaScript with clear examples and common pitfalls.
Relative Imports in Python 3: Why They Work Sometimes and Fail Other Times
Learn how relative imports work in Python 3, why import errors happen, and when to use relative vs absolute imports in packages.
Remove Duplicate Items from a Python List
Learn how to detect duplicate values in a Python list and create a new unique list while preserving order with practical examples.
Remove a Trailing Newline from a String in JavaScript
Learn how to remove a trailing newline from a string in JavaScript using safe checks, regex, and practical examples.