Sobes.tech
Intern
233

Is Python case-sensitive?

Answer from AI

sobes.tech AI

Yes, it is case-sensitive.

# Variables with different cases
variable_name = 10
VARIABLE_NAME = 20

print(variable_name)  # Will output 10
print(VARIABLE_NAME)  # Will output 20

# Functions with different cases
def my_function():
    print("Small caps")

def MY_FUNCTION():
    print("Large caps")

my_function()
MY_FUNCTION()

# Keywords
# 'if' and 'IF' are different. 'IF' will cause an error.
if True:
    print("Inside if")

# IF True: # This will cause a SyntaxError
#    print("This is not allowed")

In Python, myVariable, myvariable, and MYVARIABLE are considered different names, for variables, functions, classes, and other identifiers. The same applies to keywords like if, for, while, etc. They must be written exactly in the case defined by the language (usually lowercase).