Question 1 of 22beginner💡 UnderstandShort Answer2 marks

Which of the following identifier names are invalid and why?

(i)

Serial_no.

Answer

Invalid - Contains a special symbol '.' (dot) which is not allowed in identifiers.

(ii)

1st_Room

Answer

Invalid - Starts with a digit '1'. Identifiers cannot begin with a digit.

(iii)

Hundred$

Answer

Invalid - Contains a special symbol '$' which is not allowed in identifiers.

(iv)

Total_Marks

Answer

Valid - Follows all naming rules: starts with an uppercase letter and contains only letters and underscore.

(v)

Total_Marks

Answer

Valid - Same as (iv), follows all naming rules.

(vi)

total-Marks

Answer

Invalid - Contains a special symbol '-' (hyphen) which is not allowed in identifiers.

(vii)

_Percentage

Answer

Valid - Starts with an underscore (_) which is allowed, followed by letters.

(viii)

True

Answer

Invalid - 'True' is a keyword/reserved word in Python and cannot be used as an identifier.

Explanation

According to the textbook context, Python identifiers must follow specific rules: (1) They must begin with an uppercase/lowercase letter or underscore, and cannot start with a digit; (2) They cannot contain special symbols like !, @, #, $, %, etc.; (3) They should not be keywords/reserved words. Based on these rules, identifiers (i), (ii), (iii), (vi), and (viii) are invalid for the reasons stated above.