Question Detail

COS 102 lecture 4 Objective Question

Question

Which of the following is a valid Python identifier according to the naming conventions in the document?
Options
A 2variable
B my-variable
C total_volume
Correct Answer
D print
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 18 states, 'An identifier should not begin with a number. Hence, 2variable is not valid.' Page 17 mentions, 'Special characters such as %, @, and $ are not allowed within identifiers.' This implies '-' is also not allowed within identifiers unless it's an underscore. Page 18 also states, 'You cannot use Python keywords as identifiers,' and 'print' is listed as a keyword on page 15. 'total_volume' follows the rules of using letters and underscores, and does not start with a number.

Hint

Recall the rules for identifiers: can't start with a number, no special characters, and can't be a keyword. Review pages 17, 18, 24, and 25.

Question Info