Python Identifiers

Python · Getting Started

Theory

An identifier is any name you create: a variable, function, class or module name. The rules are strict: it must start with a letter or an underscore, may then contain letters, digits and underscores, cannot contain spaces or symbols like - or $, and cannot be a keyword. Identifiers are case-sensitive, so age, Age and AGE are three different names. The string method 'total_sales'.isidentifier() checks the spelling rules (it does not check for keywords).

Beyond the rules there are conventions from PEP 8 that every Python programmer follows: snake_case for variables and functions (total_sales), PascalCase for classes (SalesReport), UPPER_CASE for constants (MAX_ROWS), and a leading underscore (_hidden) to signal 'internal, please do not touch'. Names surrounded by double underscores, like __init__, are reserved for Python's special methods.

Why we use it

Clear, valid names make code self-explaining: monthly_revenue tells the reader far more than x2. Knowing the rules prevents SyntaxErrors, and following the conventions makes your code look familiar to every other Python developer.

When to use it

Pick descriptive snake_case names for variables and functions and PascalCase for classes. Use single letters only for short loop counters (i, j). Avoid names that differ only by case, and avoid reusing built-ins such as list, dict or id.

How it works

  1. You choose a name, e.g. 2nd_place
  2. Does it start with a letter or underscore? Yes: Check the remaining characters. No: SyntaxError: invalid name.
  3. Only letters, digits and underscores after that? Yes: Check it is not a keyword. No: SyntaxError: invalid name.
  4. Is it a keyword like class or for? Yes: SyntaxError: reserved word. No: Valid identifier.
  5. Name can be assigned, e.g. total_sales = 100

Syntax

variable_name
_private
ClassName

Example

valid_name = 1
_hidden = 2
print(valid_name, _hidden)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic