Question Detail

COS 102 lecture 4 Objective Question

Question

According to Python naming conventions, which of the following is a valid identifier?
Options
A 2variable
B my-variable
C my_variable
Correct Answer
D print@hello
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 17 states: 'An identifier can be a combination of uppercase letters, lowercase letters, underscores, and digits (0-9).' It also says 'Special characters such as %, @, and $ are not allowed within identifiers.' Page 18 adds: 'An identifier should not begin with a number. Hence, 2variable is not valid.' Therefore, 'my_variable' is valid.

Hint

Check the rules for valid identifier characters and starting characters on pages 17 and 18.

Question Info