Python Basics: Identifiers and Variables
Identifiers and Variables in Python
Introduction to Python Programming Basics
Presented by: [Your Name]
Page 1
Python Basics: Identifiers and Variables
What is an Identifier?
An identifier is the name used to identify a variable, function, class, module, or object.
It helps label data with a descriptive name.
Page 2
Python Basics: Identifiers and Variables
Rules for Identifiers
- Can contain letters (A-Z, a-z), digits (0-9), and underscores (_).
- Cannot start with a digit.
- Cannot use Python keywords (e.g., if, class, while).
- Case-sensitive: Variable and variable are different.
Page 3
Python Basics: Identifiers and Variables
Examples of Valid & Invalid Identifiers
Valid:
- my_var
- age1
- _value
Invalid:
- 1st_value
- my-var
- class (keyword)
Page 4
Python Basics: Identifiers and Variables
What is a Variable?
A variable stores data that can be used and changed later.
Python does not require declaring the type beforehand.
Page 5
Python Basics: Identifiers and Variables
Creating Variables in Python
x = 10
name = "Alice"
is_active = True
Python automatically infers the type.
Page 6
Python Basics: Identifiers and Variables
Variable Naming Conventions
- Use meaningful names: score, not s.
- Use snake_case: total_amount.
- Avoid single letters except in short loops.
Page 7
Python Basics: Identifiers and Variables
Dynamic Typing in Python
x=5
x = "Hello"
Variables can change type during execution.
Python is dynamically typed.
Page 8
Python Basics: Identifiers and Variables
Summary
- Identifiers are names for variables, functions, etc.
- Variables store data.
- Follow naming rules and conventions.
- Python supports dynamic typing.
Page 9