KnowledgeBoat Logo
|

Computer Science

Identify invalid variable names from the following, giving reason for each:

Group, if, total marks, S.I., volume, tot_strength, #tag, tag$\text{\textdollar}, 9a, for

Python Funda

1 Like

Answer

  1. Group — This is a valid variable name.

  2. if — This is an invalid variable name because if is a reserved keyword in Python and cannot be used as a variable name.

  3. total marks — This is an invalid variable name because it contains a space, which is not allowed in variable names. A variable name must be a single continuous string without spaces.

  4. S.I. — This is an invalid variable name because it contains full stops, which are not allowed in variable names. Variable names can only include letters, digits, and underscores.

  5. volume — This is a valid variable name.

  6. tot_strength — This is a valid variable name.

  7. #tag — This is an invalid variable name because it starts with a hash symbol (#), which is not allowed in variable names. Variable names must start with a letter or underscore.

  8. tag$\text{\textdollar} — This is an invalid variable name because it contains a dollar sign ($\text{\textdollar}), which is not allowed in variable names. Variable names can only include letters, digits, and underscores.

  9. 9a — This is an invalid variable name because it starts with a digit, which is not allowed in variable names. Variable names must start with a letter or underscore.

  10. for — This is an invalid variable name because for is a reserved keyword in Python and cannot be used as a variable name.

Answered By

3 Likes


Related Questions