Today, I learned about identifiers, variables, naming rules, Python keywords, the Zen of Python, IDEs, and basic data types.
Let's understand each concept with simple explanations and practical examples.
- What are Identifiers in Python?
An identifier is a name used to identify an element in a Python program.
For example:
name = 'Sanjay'
doubt = False
doubt = True
questions = 5
In this example:
-
nameis an identifier. -
doubtis an identifier. -
questionsis an identifier.
The values assigned to these identifiers are:
-
'Sanjay'– String -
True– Boolean -
5– Integer
Understanding the Assignment Operator (=)
name = 'Narasimma'
Here:
-
name– Identifier (variable name) -
=– Assignment operator -
'Narasimma'– Value
The assignment operator assigns the value on the right-hand side to the variable on the left-hand side.
- Rules for Naming Identifiers
Python follows certain rules when naming identifiers.
- Alphabets: Both lowercase and uppercase letters are allowed.
- Digits: Numbers from 0 to 9 are allowed, but an identifier cannot start with a digit.
- Underscore (_): An underscore can be used in an identifier.
Valid Identifiers
name = 'Raja'
name1 = 'Raja'
name2 = 'Sanjay'
_name = 'Megal'
Invalid Identifier
1name = 'Raja'
This is invalid because an identifier cannot start with a number.
Understanding Underscores
Python uses underscores in different ways:
-
_name– A convention indicating that the variable is intended for internal use. -
__name– Uses a double leading underscore, which triggers name mangling in classes. -
__name__– A special naming convention commonly used for Python's built-in special methods and attributes.
Top comments (0)