Is Python case sensitive when dealing with identifiers?
Select one:
a. No
b. machine dependent
c. Yes
d none of the mentioned
Which of the following is an invalid variable?
Select one:
a. 100
b. my_string-1
c. 1st string
d.
The Correct Answer and Explanation is:
✅ Correct Answers:
- Is Python case sensitive when dealing with identifiers?
Correct answer: c. Yes - Which of the following is an invalid variable?
Correct answer: a. 100
🧠 Detailed Explanation
1. Case Sensitivity in Python:
Python is a case-sensitive language, which means it distinguishes between uppercase and lowercase letters in identifiers (names of variables, functions, classes, etc.). For example, the identifiers name, Name, and NAME are all treated as distinct variables:
name = "Alice"
Name = "Bob"
NAME = "Charlie"
print(name) # Outputs: Alice
print(Name) # Outputs: Bob
print(NAME) # Outputs: Charlie
This case sensitivity applies to all identifiers, including variables, functions, and class names. It’s a critical feature for developers to remember, as mistyping the case of a variable can lead to NameErrors or logic bugs.
2. Invalid Variable Names in Python:
Python variable names must follow these rules:
- Must start with a letter (a–z, A–Z) or underscore (
_) - Can contain letters, numbers (0–9), and underscores
- Cannot start with a number
- Cannot include special characters like hyphens (
-) or spaces - Cannot be a reserved keyword (e.g.,
class,if,else, etc.)
Now, let’s analyze the options:
- a.
100❌ Invalid: It is a number, not a valid identifier. - b.
my_string-1❌ Invalid: The hyphen (-) is not allowed. - c.
1st string❌ Invalid: Starts with a digit and contains a space. - d. (Not visible, but all above are invalid, so option a is typically correct in such contexts if asked “Which is invalid”)
Among the options, 100 is clearly not an identifier at all—it’s just a numeric literal. Hence, it is the best answer when identifying the most obviously invalid variable.
Conclusion:
- Python is case-sensitive (
Yesis the correct answer). - A variable cannot be just a number like
100, so it’s an invalid identifier.
