Python Identifiers

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.

Course Video

Course Video English

YouTube Reference :

Frequently Asked Questions

Still have a question?

Let's talk

A valid Python identifier starts with a letter or an underscore (_) and can include letters, numbers, or underscores, but cannot be a reserved keyword.

A unique identifier is a name that distinctively refers to a variable, function, or class without conflict in a program.

An identifier is the name given to any entity (variable, function, or class), while a variable is a specific storage location that holds a value.

An identifier is the name of a variable, function, or class. Example: user_name, x, age.

An identifier names an entity like a variable, function, or class. A variable is an identifier specifically used to store data in a program.

An example of an identifier in Python is my_variable, which serves as a name for storing or referencing a value.

Identification refers to naming program elements like variables, functions, or objects so they can be distinctly recognized and used in the code.

Use lowercase for variables and functions, underscores for readability, and CamelCase for class names. Avoid starting with numbers or using Python keywords.

Identifiers should be descriptive, lowercase or underscored, and avoid reserved words. Example: total_count, calculate_sum.

Example: age, height, user_name.