# Integers

emalfiza

I had researched and dived to so many resources for the fundamentals of Pyhton, this is the first amazing one that I come across. Till now I didnt know we could get the Bin, Oct and Hex in python numbers… wow

Cory

May sound stupid, but why does bin(), oct(), hex() return a string? Does it have to deal with underlying programming of python seeing alphanumerics as a string? I apologize I like knowing how things work.

NICKS

There aren’t any integer hex, octal, or binary objects. There are only alternative methods of creating integer objects.

The hex, octal, or binary are just string representation of the underlying integer objects. The link below explains it in a very clearly - mail.python.org/pipermail/tutor/2008-August/063967.html

avinashk2

How to convert `bin(27)` to base 10 `int` since bin gives us string?

Bartosz Zaczyński RP Team

@avinashk2 If you call the built-in `int()` function with two parameters, the first one is expected to be a string with digits while the second one is the base of the system, for example:

``````>>> int("11011", 2)
27
``````

You can take the output of `bin(27)`, drop the `0b` prefix, and pass it back to the `int()` function:

``````>>> bin(27)
'0b11011'
>>> bin(27)[2:]
'11011'
>>> int(bin(27)[2:], 2)
27
``````

david hodson

so i am can one just used the online content, i really do not have the patents to read through the book any suggestions

to join the conversation.

Lesson Completed!
Lesson Bookmarked
Request Failed :(