Posts in Language

Format datetime easily

Formatting datetime is a common task in Python and could be a daunting task for those new to Python. Especially when you need to format datetime in a specific way and looking at the documentation can be daunting for some. The exampple below shows how to format datetime in a specific way with the time.strftime() method what can be complicated with due to all the extra lines.

Read more ...


How to use post-init with dataclasses

By default a class in Python has an __init__ method that is called when the class is instantiated. This method is used to initialize the class attributes. The example below shows this in action and how a variable is set by combining two other variables.

Read more ...


Using magic method __contains__

Python is a high level language and allows you to do a lot of things with ease. One of the things that Python allows you to do is to check if an item is present in a list or tuple for example. This is done using the in operator as shown below.

Read more ...


The NAND, NOR, and XOR operators in Python

The NAND, NOR, and XOR operators are logical operators that are not built into Python, but can be implemented using the built-in not, and, and or operators. The NAND operator returns True if and only if both of its operands are False, and the NOR operator returns True if and only if both of its operands are False. The XOR operator returns True if and only if exactly one of its operands is True.

Read more ...


Convert numbers between numerical systems

Learning to convert numbers between numerical systems is a fundamental skill in every programming language. Python provides built-in functions to convert numbers between binary, octal, decimal, and hexadecimal systems. While it seems like a simple task, it is essential to understand how to convert numbers between different numerical systems and how Python handles them.

Read more ...