Python Identifiers, Variables, and Reserved Keywords
ملخص
Pixel’s announcement explains Python identifier and variable naming rules, including valid starting characters, case sensitivity, and the use of underscores. It also shows examples and how to list reserved keywords with Python’s keyword module, helping community members avoid invalid variable names.
DEV Community
Identifiers,variables,Reserved words.
*Identifiers * A name in python program is known as identifier/variables or reference variables Rules for identifiers in Python The first character is a letter (a-z, A-Z) or an underscore _. The remaining characters are letters, digits 0-9 or underscores. It can’t be one of the reserved keywords Case matters: total and Total are consider as two different names. There’s no length limit. Name='gobi' //name is identifier
isStudent= True //isStudent is identifier
Rollno=12 //Rollno is identifier
can start with underscore() and double underscore(_) _name='gobi' //single underscore is also known as private
__rollno=13 //double underscore is also known as strictly private
Reserved Words or Keywords we can't use the keywords as identifier or variables. import keyword
print("The list of keywords are : ")
print(keyword.kwlist)
output:
The list of keywords are:
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Powered by Readybot.io