Python: How to Override Methods in Classes
Introduction Python’s object-oriented programming allows you to structure your code in a more reusable and structured way. One of the key concepts in object-oriented programming is method overriding,…
Python: Define Generic Types for Lists of Nested Dictionaries
Overview Working with nested dictionaries in Python is a common task, especially when dealing with configurations, JSON data, or complex data structures. When you start incorporating type hints…
Python: Defining type for a list that can contain both numbers and strings
Introduction In modern Python programming, especially with Python 3.5 and later versions, type hinting has become increasingly significant. Type hinting aids in the documentation of code and improves…
Using TypeGuard in Python (Python 3.10+)
Overview The introduction of Type Guards in Python 3.10 as part of PEP 647 has been a significant enhancement for developers aiming to write more explicit, readable, and…
Python: Using ‘NoReturn’ type with functions
Introduction Welcome to this deep dive into the NoReturn type in Python functions! Understanding how and when to use NoReturn can significantly improve the readability and robustness of…
Type Casting in Python: The Ultimate Guide (with Examples)
Introduction Type casting in Python is a fundamental concept that allows developers to convert variables from one type to another. This process is integral in programming because it…
Python: Using type hints with class methods and properties
Introduction Type hints in Python have significantly improved the clarity of code and made it much easier to work with large codebases or in a team environment. By…
Python: Typing a function with default parameters
Overview Python’s dynamic nature makes it flexible and easy to write code. However, with the introduction of type hints in PEP 484, Python developers now have the option…
Python: Typing a function that can return multiple types
Introduction Python, as a dynamically typed language, offers significant flexibility regarding variable types. A function in Python can return different types of data, making it versatile but challenging…
Python: Typing a function with *args and **kwargs
Introduction Python’s dynamic nature allows for flexible function definitions – among these, the use of *args and **kwargs stands out for enabling functions to accept an arbitrary number…