Scientific notation is understood by Python in two distinct senses that are easy to conflate: Python's float, int, complex, and Decimal literals accept exponent syntax such as 1e3 or 6.022e23, and functions like float() and Decimal() parse scientific-notation strings at runtime. What changes with conditions is the data type produced, the precision retained, and whether the exponent applies to a binary float, an exact decimal, or an arbitrary-precision integer. Python does not treat 1e3 as a string to interpret later; the token is compiled as a floating-point literal, so 1e3 and 1000.0 are the same runtime object value even though int("1000") yields an integer. The key condition is that exponent notation always implies a float unless you deliberately parse into Decimal or Integer-like contexts.

Literal grammar: what the tokenizer actually accepts

Python's lexical grammar defines an exponent as the letter e or E followed by an optional sign and one or more decimal digits, appended to a decimal number. So 1e3, 1E3, 1e+3, 1e-3, 6.022e23, and 0.5e-10 are valid literals. The exponent must be an integer; 1e3.5 is a syntax error. A leading sign belongs to the whole literal: -2.5e-4 is valid, but 1e- 4 with a space between sign and digits is not. Python 3 also permits underscores in numeric literals, and they may appear in the digit part: 1_000e2 is valid, but 1e1_0 is not permitted because the exponent part must be plain digits.

One common misconception is that 1e3 is an integer because it names an integer value. It is not. CPython compiles it to a float object, so type(1e3) is float and print(1e3) shows 1000.0. This matters for formatting, hashing, dictionary lookups, and for code that tests isinstance(x, int). If you need an integer from a scientific-notation string like "1e3", float("1e3") gives 1000.0, and int(float("1e3")) gives 1000, but the intermediate float can lose precision for large exponents. For an exact integer interpretation, Decimal("1e3").to_integral_value() or integer arithmetic on the coefficient and exponent is safer.

Parsing strings and JSON at runtime

Runtime parsers are more permissive about some details and stricter about others. The float() constructor accepts optional surrounding whitespace and an optional sign, then a decimal form with optional exponent: float(" 6.022e23 ") works. It also accepts "inf", "infinity", "nan", and their signed forms, case-insensitively. However, float() rejects underscores, so float("1_000e2") raises ValueError. Since Python 3.6, int() accepts underscores in strings, but int("1e3") still raises ValueError because int() does not accept exponent notation at all. That asymmetry is a frequent source of bugs when reading user input.

The json module parses numbers per the JSON grammar, which permits an exponent after a fraction or integer: {"x": 1e3} and {"x": 1E-2} are valid and become Python floats. JSON's number grammar does not permit leading plus signs or leading zeroes like 01, and json.loads enforces that. Note that reading "1e999" through float() or json yields float('inf'), because the value exceeds the binary64 range; this is silent overflow, not an exception. Conversely, tiny values like 1e-400 underflow to 0.0. If overflow or underflow must be an error, you need an explicit check with math.isfinite() after parsing.

Why the type changes precision and comparisons

The deeper mechanism is that float literals and float() route through correctly rounded binary64 conversion: the decimal token is converted to the nearest representable IEEE 754 double. That rounding happens once, at parse time, and subsequent arithmetic rounds again at each operation. Decimal is different: Decimal("1.1e1") stores the coefficient 11 with exponent 0 as exact decimal digits, so arithmetic follows the active decimal context's precision and rounding, which defaults to 28 significant digits. This produces a classic observed difference: 0.1 + 0.2 == 0.3 is False for floats but True when both sides are Decimal constructed from strings, because binary64 cannot represent 0.1 exactly.

This also explains a counterintuitive comparison. In Python 3, 1e3 == 1000 is True because the integer is converted to float for comparison and 1000 is exactly representable in binary64. But 1023 == 1e23 is False on typical platforms, because 1023 is an exact Python integer while 1e23 is the nearest binary64 value, which is not equal to 10^23. The equality rule is exact numeric comparison after type coercion, not approximate comparison. If you need tolerant comparison, use math.isclose() with explicit relative and absolute tolerances, and state what those tolerances mean in the units of your quantity.

Display, repr, and round-tripping

Python's float repr and str use the shortest decimal string that round-trips to the same binary64 value. For many values that is not scientific notation: repr(1e16) is '1e+16', while repr(1e15) is '1000000000000000.0'. Below that, repr(0.0001) is '0.0001' and repr(0.00001) is '1e-05'. So whether scientific notation appears in output depends on the magnitude and on Python's shortest-repr rules, not on how you wrote the literal. The e in repr output is lowercase and always carries a sign for the exponent: 1e-05, 1e+20.

Formatting is explicit and controlled by format specifiers. f"{x:.3e}" produces three digits after the decimal in scientific form, e.g., '1.235e+04'. The older "%e" formatting behaves similarly. Critically, formatting rounds the decimal representation of a binary value, so it displays what the float approximately is, not an exact decimal. If you must preserve a decimal literal exactly as written, Decimal keeps trailing zeros and the exponent: Decimal("1.230e2") has three significant digits and prints as '1.230E+2'. That distinction matters in finance, metrology, and any workflow where significant figures carry meaning.

Where scientific notation does and does not apply

The safe mental model is that scientific notation is a numeric grammar shared by several parsers, not a universal Python string format. A comparison clarifies the boundaries.

Context Accepts 1e3 syntax Result type Notes
Python source literal Yes float Compiled as binary64; 1e3 is float
int("1e3") No error int() rejects exponent notation
float("1e3") Yes float Allows whitespace, inf, nan
json.loads('1e3') Yes float JSON number grammar; no leading +
Decimal("1e3") Yes Decimal Exact coefficient and exponent
string to Fraction No error Fraction("1e3") raises ValueError
f-string .3e formatting Output only str Rounds the binary value for display

An edge case worth knowing is that complex literals can include exponents on real and imaginary parts, such as 1e3+2e-3j, and complex("1e3+2e-3j") parses it. Complex parsing is stricter about spacing than the literal grammar. Meanwhile, Decimal accepts "1e999999" without overflow at construction if the context allows, but arithmetic on it raises InvalidOperation when the exponent exceeds context limits. So the same notation has very different failure behavior depending on the target type.

Practical parsing pattern and common failures

For a robust conversion, decide the target type from the requirement, not from convenience. If the quantity is measured with a stated tolerance, binary64 is usually adequate; if it is money or a spec value with significant digits, use Decimal and parse the string form. A workable pattern is:

Confirm the string matches an expected numeric pattern before conversion. Use float() for physical measurements and accept binary64 rounding. Use Decimal(string) when exact decimal digits or declared precision matter. Check math.isfinite() after float parsing to catch overflow to inf or underflow to 0. Avoid int(float(s)) for large exponents; parse exactly or validate bounds first. Round only at output, with a format specifier that matches the declared precision.

The main failure conditions are the error types themselves: ValueError from int("1e3") or float("1_000e2"), silent inf/0.0 from float("1e999") or float("1e-400"), and lost precision from chaining float conversions. A practical success signal is that your parse function returns the expected type and that edge inputs such as "1e309", "-1e-400", and "1E+3" produce documented, tested outcomes rather than surprises.

Thresholds and what is being measured

Any numeric threshold mentioned with scientific notation must state the quantity, units, and interval. For binary64 floats, the largest finite value is about 1.7977e308 and the smallest positive subnormal is about 4.9407e-324; values above the first round to inf and values below the second round to 0.0 on conversion. These are properties of the storage type, not of Python's parser. For Decimal, the default context precision is 28 significant digits with an exponent range that must be configured for extreme magnitudes; Emin and Emax determine where overflow and underflow traps fire. If you compare a measured concentration of 1e-6 mol/L against a threshold of 1e-6, the comparison semantics depend on whether both sides are Decimal strings or binary floats, because the binary value of 1e-6 is close but not exactly one millionth. State the unit and the representation when a threshold decision depends on equality.

Scientific notation in Python is therefore fully understood at the lexer, parser, and formatter levels, but understanding is not the same as precision preservation. The same written token can become an exact decimal or an approximation, and the difference shows up later in comparisons, sums, and reports. Choose the target type deliberately, test the overflow and underflow boundaries, and treat display formatting as a presentation step rather than a guarantee about stored digits.