TitleCasePro logo TitleCasePro

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.

· 4 min read · Try Case Converter →

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_name
  • background_color
  • get_user_by_id
  • is_authenticated
  • created_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.

ConventionExamplePrimary use
snake_casefirst_namePython, Ruby, databases, Rust
camelCasefirstNameJavaScript, TypeScript, Java, Swift
PascalCaseFirstNameClasses, types, React components
CONSTANT_CASEFIRST_NAMEConstants, env variables
kebab-casefirst-nameURLs, 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

  1. Lowercase all lettersuser_profile, not User_Profile or USER_PROFILE.
  2. Separate words with underscoresget_user_by_id, not getuserbyid.
  3. No spaces or hyphens — only underscores as word separators.
  4. Abbreviations as single lowercase wordshtml_parser, api_key, user_id (not HTML_parser, API_key).
  5. Leading underscores — In Python, _private_method signals 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.

Related articles