-3

Variables in python(or Java) languages are case sensitive. Having said that,

When I am printing

>>> a=3.14159
>>> b=999999999999999999999
>>> print(a*b)
3.14159e+21

I can see that 'e+' (exponential) value is in lower case, where has If I use the result 'E+' (Upper case) then not seeing any error/unexpected results.?

Note: I have searched couple of links to find answers, where I found these programming languages are written to support unix based OS, however, in this exponential scenario, UNIX OS is supporting case-insensitive.?

Interested to know if these prog lang's designed to understand OS with an interpreter, then aren't these interpreters customize these sensitivity issue at all places (or where ever it applicable)

FayazMd
  • 386
  • 2
  • 22
  • Interesting, never thought about that. – Prashant Zombade Jan 24 '19 at 07:14
  • 3
    Variable _names_ are case sensitive, `3.14159e+21` is not a variable name. – Sweeper Jan 24 '19 at 07:14
  • Here you are displaying the default representation. But you don't have to take the default. In Python, when you format a floating point number for output, you can choose whether you want `E` or `e`. The two are equivalent because there is no point in distinguishing them. You can have two variables called `E` and `e` that mean different things. But suppose floating point literals were case-sensitive and only `e` meant a power-of-ten exponent, then what would `3.14159E+21` mean? It could not mean anything different, so the only other possibility would be an annoying syntax error message. – BoarGules Jan 24 '19 at 07:54
  • @Sweeper: If only variable names are case sensitive, then how about '\n' and '\N', '\t' and '\T', etc are behaving differently..?? These are also not variables, isn't it.? I believe there must be some other reasons / scenario / condition to meet.. – FayazMd Jan 24 '19 at 08:17
  • @FayazMd I didn't say "_only_ variable names". I said "variable names are case sensitive". What about the others? you ask. The others have other rules. Some are case sensitive, some are not. – Sweeper Jan 24 '19 at 08:19
  • As for *why* they designed it like this, you'd have to ask the people who designed the language. I can only speculate. – Sweeper Jan 24 '19 at 08:22

1 Answers1

1

Java and Python are case-sensitive about identifiers, that is, method names, variable names, class names etc.

3.14159e+21 is not an identifier, so the rule of "identifiers are case-sensitive" does not apply. It is a floating point literal.

In the Java Language Specification Section 3.10.5 Floating Point Literals, the syntax for a floating point literal is specified:

FloatingPointLiteral:
DecimalFloatingPointLiteral 
HexadecimalFloatingPointLiteral

DecimalFloatingPointLiteral:
Digits . [Digits] [ExponentPart] [FloatTypeSuffix] Digits [ExponentPart] [FloatTypeSuffix] 
Digits ExponentPart [FloatTypeSuffix] 
Digits [ExponentPart] FloatTypeSuffix

ExponentPart:
ExponentIndicator SignedInteger

ExponentIndicator: <---- Look at this part!
(one of) 
e E

SignedInteger:
[Sign] Digits

Sign:
(one of) 
+ -

FloatTypeSuffix:
(one of) 
f F d D

See this block?

ExponentIndicator:
(one of) 
e E

That's what makes floating point literals "case-insensitive".

Why did they design it like this? You'd have to ask them for the real answer. My guess would be that both formats (with 'e' or 'E') were already widely accepted at that time.

Sweeper
  • 213,210
  • 22
  • 193
  • 313