Python Identifier
In Python, an identifier is the name used to identify variables, functions, classes, modules, or other objects. It allows you to refer to a specific element in your program. Identifiers help in defining and using various elements in the code.
Rules for Writing Identifiers
1. Alphabet and Digits: An identifier can be a combination of letters (A-Z or a-z), digits (0-9), and underscore (_).
Examples of variable name: my_var, student1, _hiddenValue
Cannot Start with a Digit: An identifier cannot begin with a number.
Correct: age3, _score
Incorrect: 3age, 1st_student
2. No Special Characters: Identifiers cannot contain special characters like @, #, !, $, etc.
Correct: name, student_age
Incorrect: name@, student#1
3. Case Sensitivity: Python identifiers are case-sensitive. For example, Var and var are treated as different identifiers.
Example:
var = 5
Var = 10
print(var) # Output: 5
print(Var) # Output: 10
4. Keywords: Keywords (reserved words) in Python cannot be used as identifiers.
Example of Python keywords: if, else, while, for, True, False, etc.
Incorrect: You cannot name a variable for, if, True, etc.
5. Underscore (_) Usage:
An identifier can start with an underscore, which often has special meanings:
● Single Leading Underscore (_var): Used to indicate that an identifier is intended for internal use (convention, not enforced). We will learn this in detail while studying classes and objects.
● Double Leading Underscore (__var): Used for name-mangling in classes to avoid conflicts in inheritance. We will learn this in detail while studying inheritance.
● Double Leading and Trailing Underscore (__init__): Reserved for special methods in Python, often referred to as “magic methods.”
For e.g. __init_(), __repr__(), __del__(). We will learn them in detail in course.
Task :
1. Create your bio using the proper data type and proper identifier with values.