Python Print Octal Without ‘0o’

Problem Formulation If you print a hexadecimal number, Python uses the prefix ‘0o’ to indicate that it’s a number in the octal system and not in the decimal system like normal integers. However, if you already know that the output numbers are octal, you don’t necessarily need the ‘0o’ prefix. How to print oct numbers … Read more

Python Print Hex Without ‘0x’

Problem Formulation If you print a hexadecimal number, Python uses the prefix ‘0x’ to indicate that it’s a number in the hexadecimal system and not in the decimal system like normal integers. However, if you already know that the output numbers are hexadecimal, you don’t necessarily need the ‘0x’ prefix. How to print hex numbers … Read more

Python Print Binary Without ‘0b’

Problem Formulation If you print a binary number, Python uses the prefix ‘0b’ to indicate that it’s a number in the binary system and not in the decimal system like normal integers. However, if you already know that the output numbers are binary, you don’t necessarily need the ‘0b’ prefix. How to print binary numbers … Read more

How to Interleave Two Strings of Variable Lengths in Python?

Half an hour ago, my friend and coauthor of the textbook “Coffee Break NumPy” asked me the following question via WhatsApp: Problem Formulation How would you solve the problem of interleaving two strings in Python: Input: String s1= “AAA” and string s2 = “BBBBB” Output: String s=”ABABABBB” Being obsessed with finding the most Pythonic way … Read more

How to Print a NumPy Array Without Brackets in Python?

Note that this tutorial concerns NumPy arrays. To learn how to print lists without brackets check out this tutorial: How to Print a List Without Brackets in Python? Problem Formulation Given a NumPy array of elements. If you print the array to the shell using print(np.array([1, 2, 3])), the output is enclosed in square brackets … Read more