From bda177576450e415154b10a2c003d7d82af4a4e6 Mon Sep 17 00:00:00 2001 From: Ken Nguyen <30739815+kennguyen01@users.noreply.github.com> Date: Fri, 19 Oct 2018 16:40:32 -0400 Subject: [PATCH] Added example to convert int to binary (#20275) --- guide/english/python/python-f-strings/index.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/guide/english/python/python-f-strings/index.md b/guide/english/python/python-f-strings/index.md index afafbd1735..abce9be641 100644 --- a/guide/english/python/python-f-strings/index.md +++ b/guide/english/python/python-f-strings/index.md @@ -74,6 +74,20 @@ print(list_str) ``` List of fruits: Apple, Banana, Pear ``` +### Convert an integer to 8-bit binary + +### Input + +```python +num = 42 + +print(f'The binary of {num} is {num:08b}') +``` + +### Output +``` +The binary of 42 is 00101010 +``` ### Sources https://www.python.org/dev/peps/pep-0498/