Questions

Python questions

Choose a question page, learn the concept, then test your understanding with a quiz.

How to Flatten a List of Lists in Python

Learn how to flatten a list of lists in Python using loops, comprehensions, and standard library tools with clear examples.

pythonlistmultidimensional-arrayflatten

How to Get a Random Element from a List in Python

Learn how to randomly select an item from a Python list using beginner-friendly examples, syntax, pitfalls, and practical use cases.

pythonlistrandom

How to Get an Object's Class Name in Python

Learn how to get the class name of an object in Python using __class__, type(), and __name__ with examples and common mistakes.

pythonintrospectioninstanceofpython-datamodel

How to Get the Current Time in Python

Learn how to get the current time in Python using datetime and time modules with simple examples, explanations, and common mistakes.

pythondatetimetime

How to Get the Last Element of a List in Python

Learn how to get the last element of a list in Python using negative indexing and length-based indexing with clear examples.

pythonlistindexing

How to Get the Length of a List in Python

Learn how to get the number of elements in a Python list using len(), with examples, common mistakes, and practical use cases.

pythonlist

How to Get the Row Count of a Pandas DataFrame in Python

Learn how to get the number of rows in a pandas DataFrame using shape, len(), and other practical Python examples.

pythonpandasdataframe

How to Implement a Singleton in Python: Patterns, Tradeoffs, and Pythonic Alternatives

Learn singleton implementation in Python using modules, __new__, decorators, and metaclasses, with tradeoffs and Pythonic guidance.

pythonsingletondecoratorbase-class

How to Import Python Files from a Different Folder

Learn how Python imports work across folders, packages, and project structure with clear examples and fixes for common import errors.

pythonimporterrorpython-import

How to Import a Module Dynamically by Full File Path in Python

Learn how to dynamically import a Python module from a full file path using importlib, with examples, pitfalls, and practical use cases.

pythonpython-importpython-module

How to Install Python Packages from requirements.txt Using pip and a Local Directory

Learn how pip installs packages from requirements.txt and a local directory, why installs may appear to work, and how to verify them in Python.

pythonpipvirtualenvrequirements.txt

How to Install a Specific Package Version with pip in Python

Learn how to install a specific package version with pip in Python, verify what was installed, and troubleshoot version mismatch issues.

pythonmysqlpippypi

How to Install pip on Windows for Python

Learn how to install pip on Windows, what pip does, and the safest ways to get it working for Python projects and packages.

pythonwindowspip

How to Iterate Over Rows in a Pandas DataFrame in Python

Learn how to iterate over Pandas DataFrame rows in Python, understand iterrows and itertuples, and choose the right approach.

pythonpandasdataframeloops

How to Limit Floats to Two Decimal Places in Python

Learn why Python floats show values like 13.949999999999999 and how to round, format, and use Decimal correctly for 2 decimal places.

pythonfloating-pointroundingprecision

How to List All Files in a Directory in Python

Learn how to list files in a directory in Python using os.listdir, os.scandir, and pathlib with practical examples and common mistakes.

pythondirectory

How to Lowercase a String in Python

Learn how to convert a string to lowercase in Python using built-in string methods, examples, common mistakes, and practical use cases.

pythonstringuppercaselowercase

How to Measure Elapsed Time in Python

Learn how to measure elapsed time in Python using time, perf_counter, and timeit with simple examples and common mistakes.

pythonperformancemeasuretimeit

How to Measure Python Program Execution Time

Learn how to measure the execution time of a full Python program using time and perf_counter with clear examples and common pitfalls.

pythontimeexecution-time

How to Merge Two Dictionaries in a Single Expression in Python

Learn how to merge two dictionaries in Python, including single-expression syntax, overwrite rules, examples, mistakes, and best practices.

pythondictionarymerge

Page 3 of 6 - 112 questions