According to the python help(hex)
call, the function hex()
can only receive an integer. But now I realize that it can also receive other types of numbers and I'm curious to know about what feature of python or its modules makes this possible.
The Python console below is of version 3.8 but I received the same output of hex()
on 2.7.
>>> hex(0o20)
'0x10'
>>> hex(0b10000)
'0x10'
>>> hex(16)
'0x10'
>>> help(hex)
Help on built-in function hex in module builtins:
hex(number, /)
Return the hexadecimal representation of an integer.
>>> hex(12648430)
'0xc0ffee'
>>>
PD: What does the forward slash on hex(number, /)
mean? I tried adding two arguments to the function call but the return states that hex()
can only receive one argument.