Python’s string format method can take a format spec.
>>> "{0:b}".format(37)
'100101'
Format spec docs for Python 2
Format spec docs for Python 3
Related Contents:
- Python int to binary string?
- I want to convert 1fd93d1cf1f13d0d to 00011111 11011001 00111101 00011100 11110001 11110001 00111101 00001101
- What does the ‘b’ character do in front of a string literal?
- Reading binary file and looping over each byte
- Convert binary to ASCII and vice versa
- How to convert string to binary?
- Bitwise operation and usage
- Converting integer to binary in python
- Fast way of counting non-zero bits in positive integer
- How to convert ‘binary string’ to normal string in Python3?
- Flask to return image stored in database
- Reading a binary file with python
- Python 2.x – Write binary output to stdout?
- Convert hex to binary
- Convert hex to float
- How can I detect if a file is binary (non-text) in Python?
- Binary representation of float in Python (bits not hex)
- Convert to binary and keep leading zeros
- How do you express binary literals in Python?
- Binary numpy array to list of integers?
- Remove ‘b’ character do in front of a string literal in Python 3 [duplicate]
- How to read bits from a file?
- Execute .exe file embedded in Python script
- Serializing binary data in Python
- Reading integers from binary file in Python
- Convert binary string to bytearray in Python 3
- Convert decimal to binary in python [duplicate]
- Python OpenCV convert image to byte string?
- Are dictionaries ordered in Python 3.6+?
- How to delete a specific line in a file?
- how to play wav file in python?
- Capturing repeating subpatterns in Python regex
- return statement in for loops
- python pandas: apply a function with arguments to a series
- Can you explain closures (as they relate to Python)?
- How to read numbers from file in Python?
- Python/NumPy first occurrence of subarray
- How to get the index of a maximum element in a NumPy array along one axis
- Pandas sum by groupby, but exclude certain columns
- Create file but if name exists add number
- Is the single underscore “_” a built-in variable in Python?
- Get files names inside a zip file on FTP server without downloading whole archive
- When to use sys.path.append and when modifying %PYTHONPATH% is enough
- “Anti-merge” in pandas (Python)
- Running Python scripts with Xampp
- Difference between abstract class and interface in Python
- Converting string to datetime object
- How to append to a JSON file in Python?
- Single legend for multiple axes [duplicate]
- How to get faster code than numpy.dot for matrix multiplication?