Is Python case-sensitive when dealing with Identifiers?

276    Asked by CharlesParr in Python , Asked on Dec 20, 2023

 In the context of Python programming language, I defined a variable named “myVar” and another variable named “myvar”. How would both these two variables be treated in the same Python script considering if Pythoncase-sensitivities when dealing with Identifiers or not? 

Answered by Chloe Burgess

 In the context of Python, if you do not know is Python case-sensitive when dealing with Identifiers? Therefore, it means you have to type variables, functions, classes, and other Identifiers with the same combination of uppercase and lowercase alphabets.

For example, in your particular case the variable named “myVar” would be treated differently as compared to “myvar”. Here is the instance given:-

myVar = 10
mylar = 20
Print(myVar) # Output: 10
Print(myvar) # Output: 20

By looking at the above instance, it is clear that Python distinguished between both Identifiers based on their case. Hence, the python would treat differently to both Identifiers within the same script.



Your Answer

Interviews

Parent Categories