KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Which out of the following is a valid variable name?

  1. @val
  2. 9val
  3. _val
  4. int

Getting Started

1 Like

Answer

_val

Reason — According to the rules for declaring variable names in Python, a variable name must start with a letter (capital or small) or an underscore (_). It can consist only of letters, digits, and underscore, variable names are case-sensitive, and Python keywords should not be used as variable names.

  1. @val — Invalid, because special characters like @ are not allowed in variable names.
  2. 9val — Invalid, because a variable name cannot start with a digit.
  3. _val — Valid, because it starts with an underscore and follows all the rules of variable naming.
  4. int — Invalid, because int is a Python keyword and keywords cannot be used as variable names.

Answered By

2 Likes


Related Questions