What is the difference between overloading and overriding in Python?
Python keeps one method per name, so overloading is simulated, while overriding works natively. See both with runnable Python 3.12+ examples.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Python keeps one method per name, so overloading is simulated, while overriding works natively. See both with runnable Python 3.12+ examples.
A class is the blueprint, an instance is an object created from it. Compare class and instance attributes, methods and common pitfalls.
self is the conventional first parameter of Python instance methods. It refers to the object the method was called on and gives access to its attributes.
Python calls __init__ right after creating an object so you can set its attributes. Learn defaults, validation, super().__init__() and how it differs from __new__.
A namedtuple is an immutable tuple with named fields, so code reads better at almost no cost. See examples, methods and when to use a dataclass.
A for loop walks through an iterable, and a while loop repeats as long as a condition holds. Learn which to choose, with examples and common mistakes.
break ends the whole loop right away, while continue only skips the rest of the current iteration. Examples cover for, while, for-else and nested loops.
A Python lambda is a small anonymous function for quick inline logic. See when to use it for sorting, map and filter, and when to choose def instead.
A Python list holds any objects, while an array stores one numeric type compactly. See array.array and NumPy compared with the list, with code.
__str__ is the friendly text shown by print and str(), and __repr__ is the developer-facing form used by repr() and the REPL. See examples and rules.
Create classes in Python with __init__, attributes, methods, properties and inheritance, and use dataclasses to avoid boilerplate in modern Python.
Create Python generators with yield or generator expressions, and use them for lazy, memory-efficient iteration over large or infinite data.
yield makes a function return a generator that produces values one at a time and keeps its state between them, saving memory on large or streaming data.
Learn how *args and **kwargs work in Python, how to combine them with normal and keyword-only parameters, and how to unpack arguments in a call.
Build a typed singly linked list in Python with append, prepend, delete, search and reverse, and learn when list or deque is the better choice.
Shallow copies share inner objects, deep copies duplicate everything. See copy.copy and copy.deepcopy with examples and common pitfalls.
__del__ is Python's finalizer, run when an object is garbage collected, but its timing is not guaranteed. Learn the pitfalls and safer cleanup patterns.
Learn how to turn C error codes into Python exceptions with ctypes, using errcheck, use_errno and get_errno for reliable error handling.
There is no WinFunction in ctypes. Compare WinDLL with CDLL, learn what stdcall means, and see how to declare Windows API function prototypes safely.
Learn how to load a shared library with ctypes, declare argtypes and restype, and pass integers, floats and strings to a C function.