Southern University Bangladesh
Department of Computer Science and Engineering
TITLE OF THE LAB REPORT
Check Whether a Given Identifier is Valid or Not in Python
Course Code: CSE 0611-418
Course Title: Compiler Design Lab
Fall 2025
1. Name : MD Taimur ALam
2. Student ID : 666-59-29
3. Batch : 59th Batch
4. Email ID : Taimuralam01810000@gmail.com
5. Date of Assignment : 17-8-2025
6. Date of Submission : 17-8-2025
7. Contact No : 01885398859
8. Signature of Student :
9. Course Teacher : Ishraq Samiha
10. Signature of Teacher :
Lab Report:4
Objective:
Understand Python identifier rules.
Validate a user-input identifier.
Learn to use isidentifier() and the keyword module.
Necessary IDE and Tools:
Tool Description
Python (v3.6+) Programming language
VS Code / PyCharm IDE for coding and execution
Any Text Editor To create source file (code.txt)
Command Prompt / Terminal To run the script
Description
A Python identifier is the name of a variable, function, or class.
Rules for a valid identifier:
1. Cannot start with a number.
2. Can contain letters (a-z, A-Z), digits (0-9), or underscore _.
3. Cannot be a reserved keyword (e.g., for, if, while, etc.).
This experiment validates a user input based on these rules.
Page 2 | 6
Code and Sample Input-Output :
Python code:
Page 3 | 6
Expected Output:
Page 4 | 6
Discussion:
The program uses isidentifier() to check syntax rules.
keyword.iskeyword() ensures the identifier is not a reserved keyword.
By combining both, the program correctly validates identifiers.
Users can easily check whether a name is valid for a variable, function, or class.
Conclusion
The experiment successfully demonstrates how to validate a Python identifier using built-in functions.
Using isidentifier(), we can check if the input follows the correct syntax rules.
Using keyword.iskeyword(), we ensure that reserved keywords are not used as identifiers.
This helps prevent syntax errors and ensures proper naming of variables, functions, and classes in
Python.
Overall, the program is a simple and effective way to validate identifiers before using them in Python
code
Page 5 | 6
Page 6 | 6