What Is snake_case in Programming? Rules and Examples | TitleCasePro
snake_case separates words with underscores and uses all lowercase. It is the standard naming convention in Python, Ruby, and SQL database schemas.
Quick answer: snake_case separates words with underscores and uses all lowercase letters — like
first_nameorget_user_by_id. It is the standard for variables and functions in Python and Ruby, and for column names in SQL databases.
snake_case is a naming convention where words in an identifier are separated by underscores (_) and all letters are lowercase. The name comes from the visual resemblance to a snake lying flat — the underscores form a long, low shape between words.
Examples:
first_namebackground_colorget_user_by_idis_authenticatedcreated_at
Key rule: All letters are lowercase. Words are separated by underscores. No spaces, no hyphens, no capital letters — just
words_like_this.
Where snake_case Is Used
Python (official standard — PEP 8)
def get_user_profile(user_id):
first_name = db.query(user_id).first_name
return first_name
Python’s official style guide, PEP 8, mandates snake_case for variables, functions, methods, and module names.
Ruby
def calculate_total_price(items)
items.sum { |item| item.unit_price }
end
Database columns (SQL)
Most databases (PostgreSQL, MySQL, SQLite) use snake_case for table and column names because SQL is case-insensitive and underscores are cleaner than hyphens in SQL syntax:
SELECT first_name, last_name, created_at FROM user_profiles;
Rust
The Rust compiler actively enforces snake_case for variables and functions and emits a warning if you use any other convention.
Environment variables (CONSTANT_CASE)
When snake_case is written in all uppercase, it becomes CONSTANT_CASE (also called SCREAMING_SNAKE_CASE), which is the convention for constants and environment variables in most languages.
MAX_CONNECTIONS = 100
DATABASE_URL = os.environ["DATABASE_URL"]
snake_case vs. camelCase
These are the two most common naming conventions in programming — and the most common source of cross-language confusion.
| Convention | Example | Primary use |
|---|---|---|
snake_case | first_name | Python, Ruby, databases, Rust |
camelCase | firstName | JavaScript, TypeScript, Java, Swift |
PascalCase | FirstName | Classes, types, React components |
CONSTANT_CASE | FIRST_NAME | Constants, env variables |
kebab-case | first-name | URLs, CSS classes, HTML attributes |
⚠️ The most common mismatch: A Python API returns
{ "first_name": "Alice" }(snake_case). A JavaScript frontend expects{ firstName: "Alice" }(camelCase). Always check which convention your API uses and configure your serialization library to convert automatically.
Rules for Writing snake_case
- Lowercase all letters —
user_profile, notUser_ProfileorUSER_PROFILE. - Separate words with underscores —
get_user_by_id, notgetuserbyid. - No spaces or hyphens — only underscores as word separators.
- Abbreviations as single lowercase words —
html_parser,api_key,user_id(notHTML_parser,API_key). - Leading underscores — In Python,
_private_methodsignals internal/private use. In most other languages, avoid leading underscores unless the language has a specific convention for it.
CONSTANT_CASE (SCREAMING_SNAKE_CASE)
When you need to signal that a value is a constant — something that should never change at runtime — write it in all uppercase snake_case:
const MAX_RETRIES = 3;
const API_BASE_URL = process.env.API_BASE_URL;
MAX_CONNECTIONS = 100
DATABASE_URL = os.environ["DATABASE_URL"]
The all-caps signals to any reader: “this value is fixed, do not modify it.”
Converting Between Cases
When you need to convert between snake_case and other conventions — such as converting a database column name to a JavaScript variable — the case converter handles all conversions simultaneously.
Paste first_name and it immediately shows:
firstName(camelCase)FirstName(PascalCase)FIRST_NAME(CONSTANT_CASE)first-name(kebab-case)
All at once, with a single click to copy any format.
Developer Naming Conventions
Ready to try it?
Use our free Case Converter to apply these rules instantly — no signup required.
Open Case Converter →Related articles
How Long Does It Take to Read and Speak Text? (WPM Reference)
Reading time and speaking time are calculated from word count. Here are the exact formulas, average WPM rates by context, and a comparison table for common content lengths.
How to Clean Up Messy Text — Remove Line Breaks, Spaces, and Duplicates
A practical guide to fixing common text formatting problems: extra line breaks from PDFs, double spaces, blank lines, and duplicate entries. Includes one-click fixes.
How to Extract Email Addresses From Text (Any Format)
Learn how to extract email addresses from plain text, HTML, CSV files, and logs instantly — and which patterns count as valid emails.
How to Extract URLs From Text — Links, Hrefs, and Bare Domains
How to pull all URLs and links out of any text — HTML source, Markdown, log files, or plain prose — and get a clean deduplicated list.