How to use f-strings In Python

F-strings helps to embed python expressions inside string literals for formatting. 

Python3




# Using f-string
print(f"{-32:b}")


Output : 

-100000

Time Complexity : O(1)

Space Complexity : O(1)

Note: For more information about Representation of Negative Binary Numbers please read this article – Click



Python program to Represent Negative Integers in binary format

Given a Negative Integer, the task is to write a Python program to convert the integer into binary format. 

Examples:

Input: -14
Output: -1110

Input: -12
Output: -1100

Input: -32
Output: -100000

Let’s implement this for the number in different ways :

Similar Reads

Method 1: Using format specifier ‘b’

In format specifier type b is used to convert the integer into binary form....

Method 2: Using bin() function

...

Method 3: Using f-strings

Python bin() function returns the binary string of a given integer....