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.

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.

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

Best,
Niles.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.