Take the 2-minute tour ×

Conventionally 1e3 means 10**3.

>>> 1e3
>>> 10**3

Similar case is exp(3) compared to e**3.

>>> exp(3)
>>> e**3

However now notice if the exponent is a float value:

>>> exp(3.1)
>>> e**3.1

which is fine. Now for the first example:

>>> 1e3.1
  File "<stdin>", line 1
SyntaxError: invalid syntax
>>> 10**3.1

which shows Python does not like 1e3.1, Fortran too. Regardless it could be a standard (!) why it is like that?

share|improve this question

closed as not constructive by Marc B, plaes, Nifle, Lukas Knuth, Shafik Yaghmour May 11 '13 at 17:25


why does visual basic use ' as the comment char, which in any other non-insane language is used for strings? it's how the language designers wanted it. if you want to rant, rant at them. –  Marc B May 11 '13 at 4:44
@MarcB Think always positive, then you will notice the point behind the question. Your example ' is not relevant! –  Developer May 11 '13 at 5:15
I, for one, do not see why I am not allowed to write 2(1.5)3 for 218. –  Pascal Cuoq May 11 '13 at 13:44
add comment

3 Answers

up vote 9 down vote accepted

The notation with the e is a numeric literal, part of the lexical syntax of many programming languages, based on standard form/scientific notation.

The purpose of this notation is to allow you to specify very large/small numbers by shifting the point position. It's not intended to allow you to encode multiplication by some arbitrary power of 10 into numeric literals. Therefore, that point and the following digits aren't even recognised as part of the numeric literal token.

If you want arbitrary powers, as you've found, there are math functions and operators that do the job. Unlike a numeric literal, you even get to determine the parameter values at run-time.

share|improve this answer
add comment

You seem to be conflating syntax for literals with operators. While you can claim that 1e3.1 follows your "convention" it should be quite clear that 1e3.1 is not a valid literal expression to the Python interpeter. The language has a defined standard grammar, and that grammer doesn't support floating point literal expressions as "exponents" for its numeric literals.

The "e" in a Python numeric literal is not an operator (any more than the decimal point would be). So your expectation that Python's literal syntax should support some "convention" ... based on some pattern you've divined ... is not particularly reasonable.

share|improve this answer
Thanks + one upvote. Apparently it is just an agreement done already, otherwise, it would not be that difficult recognising 1e3.1 as a number by compiler. BTW it is the same in Fortran. –  Developer May 11 '13 at 5:12
Our answers passed in the 'net. I saw yours come in after mine was posted even though it appeared above mine. –  Jim Dennis May 11 '13 at 5:14
add comment

From the docs:

sign           ::=  '+' | '-'
indicator      ::=  'e' | 'E'
digits         ::=  digit [digit]...
exponent-part  ::=  indicator [sign] digits            #no dots allowed here  
share|improve this answer
Nice + upvote. BTW it is the same in Fortran. Would be better if you could try explain why. –  Developer May 11 '13 at 5:13
@Developer programming languages try to stick to the IEEE floating point standard, which says that the exponent part must be an integer. –  undefined is not a function May 11 '13 at 5:31
Thanks for the point and link, Ashwini. –  Developer May 11 '13 at 7:01
add comment
