integer's methods

Igor Korot ikorot01 at gmail.com
Thu Aug 18 09:08:40 EDT 2016


Hi,

On Thu, Aug 18, 2016 at 8:58 AM, ast <nomail at com.invalid> wrote:
> Hello
>
> I wonder why calling a method on an integer
> doesn't work ?

123 is not an integer. Its an integer constant. ;-)

Thank you.

>
>>>> 123.bit_length()
>
> SyntaxError: invalid syntax
>
>>>> 123.to_bytes(3, 'big')
>
> SyntaxError: invalid syntax
>
> but it works with a variable
>
>>>> i = 123
>>>> i.bit_length()
>
> 7
>
>>>> i=123
>>>> i.to_bytes(3, 'big')
>
> b'\x00\x00{'
>
> I am working with pyhton 3.5.1
>
> thx
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list