0

If I execute the following code in python on CPython interpreter, it works as expected:

A = 1
a = 2
print(A)
print(a)

Output:

1
2

The question is will this behavior persist with other implementations of Python interpreters? Can I rely on this and produce such a code?

6
  • Yes you can do that Commented May 12, 2020 at 21:45
  • 1
    'systems that consider different case of the same letter to be the same' - which system would that be, and what exactly do you mean by that? Commented May 12, 2020 at 21:52
  • 2
    are you thinking of Windows file-paths, which are case-insensitive? That's not at all relevant to Python code: Python variables are always case sensitive, and the underlying operating system the code is running on is irrelevant. Commented May 12, 2020 at 21:54
  • 1
    Yes, this will work on all systems. The python interpreter is case-sensitive, regardless of the platform. Commented May 12, 2020 at 21:55
  • A != a. Python interpreter is case sensitive. These are two different objects. Commented May 12, 2020 at 22:10

1 Answer 1

2

These effectively are just two different variables, so I would imagine that this behaviour will persist in all systems.

By convention, constants are upper-case. However, Python is seeing two completely different variables, as it's a case-sensitive language.

Not entirely sure if relevent, but see here for naming conventions.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Re names: I used A and a just as an example, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.