Questions
Python questions
Choose a question page, learn the concept, then test your understanding with a quiz.
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.
How to Write JSON Data to a File in Python
Learn how to write a Python dictionary to a JSON file correctly using json.dump and json.dumps with simple examples.
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 @classmethod vs @staticmethod Explained for Beginners
Learn what @classmethod and @staticmethod mean in Python, how they differ from instance methods, and when to use each one clearly.
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 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 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 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.
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 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.
Running Python on Android: Options, Limitations, and Practical Approaches
Learn how Python can run on Android, including CPython, Jython limits, app-building options, and practical ways developers use Python on Android.
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.