954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

General Python question

Hi

Everything in Python is treated as an object, so

i=5
i.imag


makes sense, i.e. the variablei 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.

Niles64
Newbie Poster
10 posts since Aug 2011
Reputation Points: 10
Solved Threads: 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.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

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

Best,
Niles.

Niles64
Newbie Poster
10 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You