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.

pythonglobal-variablesscope

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.

pythonjson

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.

pythonloopsdictionarykey

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.

pythonsyntaxparameter-passingvariadic-functions

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.

pythonoopstatic-methodsclass-method

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.

pythonreferenceparameter-passingpass-by-reference

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.

pythondirectory

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.

pythonfunctiondecoratorpython-decorators

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.

pythonlistdata-structuresappend

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.

pythonlanguage-designdefault-parametersleast-astonishment

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.

pythonpython-importrelative-pathpython-packaging

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.

pythonclassstaticclass-variables

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.

pythonstringsubstringcontains

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.

pythonstringsubstring

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.

pythonvirtualenvvirtualenvwrapperpyenv

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.

pythonstringrandom

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.

pythonpython-3.xpython-import

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.

pythonnewlinetrailing

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.

pythonandroidjythonase

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.

pythonpandasdataframeindexing

Page 5 of 6 - 112 questions