#C12204. Valid Python Identifier
Valid Python Identifier
Valid Python Identifier
Given a string, determine whether it is a valid Python identifier.
A valid Python identifier must satisfy the following conditions:
- The string is non-empty.
- The first character is either a letter (a-z or A-Z) or an underscore ('_').
- Each subsequent character is either a letter, a digit, or an underscore.
This can be expressed mathematically using LaTeX as follows:
$$ s \neq \epsilon, \quad s[0] \in [a-zA-Z\_] \quad \text{and} \quad \forall i \geq 1,\, s[i] \in [a-zA-Z0-9\_] $$
Write a program that reads an input string and outputs True
if it is a valid Python identifier, otherwise outputs False
.
inputFormat
The input consists of a single line containing the string to be checked. Any leading or trailing whitespace should be ignored.
outputFormat
Output a single line: True
if the input string is a valid Python identifier, and False
otherwise.
variable
True