1

Hi

Everything in Python is treated as an object, so

i=5
i.imag

makes sense, i.e. the variable i has some associated methods. But why doesn't the following example work?

5.imag #error

One would think that it should work, since the integer "5" is an object just like the list "[1,2]":

[1,2].pop() #no error

Best,
Niles.

Edited by Niles64: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Niles64
0

Interesting syntax point, however the:

(5).imag

does work as does

int(5).imag

I thought it is because the constant could be floating point number, and it makes sense that:

5.4.imag

is not valid syntax, but actually it is accepted by interpreter.

Edited by pyTony: n/a

0

Ah, I see. OK, so it makes sense afterall. Thanks!

Best,
Niles.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.