0% found this document useful (0 votes)
6 views3 pages

Python Identifiers

Identifiers in Python are names assigned to entities such as classes, functions, and variables, following specific rules. They can include letters, digits, and underscores, but cannot start with a digit, use keywords, or contain special symbols. Python is case-sensitive, and valid identifiers can be of any length, with examples provided for both valid and invalid identifiers.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Identifiers

Identifiers in Python are names assigned to entities such as classes, functions, and variables, following specific rules. They can include letters, digits, and underscores, but cannot start with a digit, use keywords, or contain special symbols. Python is case-sensitive, and valid identifiers can be of any length, with examples provided for both valid and invalid identifiers.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Identifiers

An identifier is a name given to entities like class, functions,


variables, etc. It helps to differentiate one entity from another.

Rules for writing identifiers


1. Identifiers can be a combination of letters in lowercase (a to z) or
uppercase (A to Z) or digits (0 to 9) or an underscore _. Names
like myClass, var_1 and print_this_to_screen, all are
valid example.
2. An identifier cannot start with a digit. 1variable is invalid,
but variable1 is a valid name.
3. Keywords cannot be used as identifiers.

global = 1

Output
File "<interactive input>", line 1
global = 1
^
SyntaxError: invalid syntax
4. We cannot use special symbols like !, @, #, $, % etc. in our
identifier.
a@ = 0

Output
File "<interactive input>", line 1
a@ = 0
^
SyntaxError: invalid syntax

5. An identifier can be of any length.

Python is a case-sensitive language. This


means, Variable and variable are not the same.

Multiple words can be separated using an underscore,


like this_is_a_long_variable

Python Valid Identifiers Example


 abc123

 abc_de

 _abc

 ABC

 abc

Python Invalid Identifiers Example


 123abc
 abc@

 123

 for

You might also like