What is Identifier ?
A name in python program is known as Identifier / Reference variable /variable
A used-defined name to discribe something to machine.
Rules of declaring Identifiers
- Starts with alphabets[lowerCase / upperCase ]
- Digits are permitted , but should not starts with digits
- Using UnderScore(_) -Should not to use reserved Keywords
###Valid Identifiers Name = "Ajay" name = "Ajay" name1 = Ajay" newName = "Ajay" New_name = "Ajay" _Name = "Ajay" __Name = "ajay" __name__ = "ajay" ###Invalid Indentifers 1name = "ajay" new name = "ajay" class ="ajay" # class is the reserved keyword new-Name = "ajay" Rule of UnderScore in Python
- _name --->(#private):
A single underscore indicates that a variable or method is intended for internal use.
Please treat this as internal
class Student: def __init__(self): self._marks = 90 s = Student() print(s._marks) - __name --->(#Strictly private):
A double underscore before a name triggers name mangling. Python changes the attribute's internal name to reduce accidental access and naming conflicts.
Reduce accidental access and naming conflicts
class Student: def __init__(self): self.__marks = 90 s = Student() # print(s.__marks) # AttributeError print(s._Student__marks) - name --->(Special methods):
Double underscores on both sides identify special names used by Python. They are often called dunder names.
Python special method or attribute
class Student: def __init__(self, name): self.name = name def __str__(self): return self.name s = Student("Ajay") print(s) Reserved Words
Reserved words are known as keywords are predefined, case Senstive identifier used in language to fidn the syntax and structure.
- Reserved words should not be an identifies , function , object
- 30+ keywords in python
Reserved words 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']