Converting int to String
Converting a Python int to a string. In Python, you can convert a Python int to a string using
str(), as seen here. As you can see,
i is an integer and we can obtain the string representation, as seen here.
00:45 In this example, it’s smart enough to interpret the binary literal and convert it to a decimal string. If you want a string to represent an integer in another number system, then you can use a formatted string such as an f-string in Python 3.6 and later, and an option that specifies the base as seen here.
:x representation has converted to hexadecimal. And using
:b has converted the number to binary. This gives a flexible way to represent an integer in a variety of different number systems.
Become a Member to join the conversation.