DEV Community

gobi2023
gobi2023

Posted on

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)