See Python PEP 8: Function and Variable Names:

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

Variable names follow the same convention as function names.

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

Answer from S.Lott on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_variables_names.asp
Python - Variable Names
Python Examples Python Compiler ... (age, carname, total_volume). Rules for Python variables: A variable name must start with a letter or the underscore character ·...
🌐
Reddit
reddit.com › r/python › follow these rules to write python variables names like a pro.
r/Python on Reddit: Follow these rules to write PYTHON variables names like a PRO.
September 20, 2022 -
  • We have to agree that variables names are an essential part of the source code and meaningful names are important when it comes to program comprehension.

  • They serve as an implied documentation that should convey to the reader;

  • Considering that sometimes names are the only documentation, then clean code approach should be highly regarded.

  • Therefore, it is important to devote a considerable amount of time to the issue of variable naming and therefore the variable names and rules.

Variable Names Rules & Guidelines

  • A variable name CAN be one word, though not a Must

  • You SHOULD separate words with underscores and not spaces.

  • When naming variable's we SHOULD only use alpha-numeric characters (letters and numbers) and the underscore character.

  • You SHOULD NOT start a variable name with a number, but can start with a letter or an underscore character. Breaking this rule will give you an invalid decimal literal or syntax error

  • A variable name SHOULD start with a letter or the underscore character.

  • You SHOULD NOT use python keywords and function names as variable names.

  • Variable names are case sensitive message, Message, MESSAGE and MeSsAge are different

  • Ensure that variable names are; Short: though they can be long. Descriptive: That is can tell what the variable is used for.

  • Take note that some letters like lowercase l and uppercase letter O can easily be confused with number 1 and 0.

  • While it is legal to use upper case letters; Others think it is a good idea to start variable names with lower case letter. Others believe that they better use camel case than separate names with_ . Others avoid starting variables names with an underscore, unless when they are writing library code.

References and further reading.

Watch this for code examples

Discussions

What is the naming convention in Python for variables and functions? - Stack Overflow
While this answer is somewhat old, ... with Python. Time has shown that it's pretty easy to get style rules across many libraries consistent regardless of the early variations in the standard library, hence the existence of tools like Black which help all code read the same for greater efficiency. 2024-05-07T05:22:49.563Z+00:00 ... As mentioned, PEP 8 says to use lower_case_with_underscores for variables, methods and ... More on stackoverflow.com
🌐 stackoverflow.com
Best practices for naming variables: what the research shows
So the gist of the article is useful, but I have to question some of the specifics. For example, the indicating of new words with capital letters — or separating words with an underscore in the so-called “snake case” can both slow comprehension. Common sense says that run-on names are also hard to read, so the moral is... what? Variable names increase cognitive load? If a variable only holds the values “true” or “false”, end its name with a question mark. None of the languages I work with support that. C# is the closest, but it indicates that the variable is nullable. More on reddit.com
🌐 r/coding
23
75
June 3, 2022
Are underscored variable naming convention used commonly in industry?
Yes. At every company I've worked for we were always quite strict about adhering to the style guidelines: https://www.python.org/dev/peps/pep-0008/ CONSTANT_NAMES ClassNames variable_and_function_names More on reddit.com
🌐 r/learnpython
18
5
May 13, 2021
Go to variable names?
i for integer index iteration. Actual descriptive names for other variables, even for scratch code. Too often have I seen scratch code passed to others, committed, or (worst of all) pushed into production. So proper variable names are a habit I try to enforce unless its literally a file I guarantee will be deleted before any other human sets eyes on it. Even then, if I'm summing something up, I'll always called it summed instead of just s. More on reddit.com
🌐 r/Python
132
29
January 21, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-variables
Python Variables - GeeksforGeeks
Unlike Java and many other languages, Python variables do not require explicit declaration of type. The type of the variable is inferred based on the value assigned. ... Variable names can only contain letters, digits and underscores (_).
Published   2 weeks ago
🌐
Real Python
realpython.com › python-variables
Variables in Python: Usage and Best Practices – Real Python
January 12, 2025 - What are best practices for naming variables in Python?Show/Hide · Use descriptive and meaningful names, follow the snake case convention for multi-word names, and avoid using keywords or built-in names.
🌐
Codefinity
codefinity.com › courses › v2 › 2f60173b-9829-4c84-8548-85bf65183f71 › 984eb7ed-25b1-40e1-93d0-3f7991547ac9 › 9078d240-0669-41e4-a40c-9e4538c36fad
Learn Variable Naming Rules | Variables and Types
Variable names should only contain letters, numbers, and underscores. For example, item_name1 is fine, but avoid using special characters like dashes (item-name is invalid). Python treats uppercase and lowercase letters as different.
Find elsewhere
🌐
Luis Llamas
luisllamas.es › inicio › cursos › curso python
Rules for naming variables in Python
November 20, 2024 - Name Start: The variable name must start with a letter (a-z, A-Z) or an underscore (_). It must not start with numbers or other characters. variable = 42 _private_variable = "Python" 1variable = "Error" # Incorrect, should not start with a number
🌐
Python
peps.python.org › pep-0008
PEP 8 – Style Guide for Python Code | peps.python.org
Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability. Use one leading underscore only for non-public methods and instance variables...
🌐
freeCodeCamp
freecodecamp.org › news › python-variables
Python Variables – The Complete Beginner's Guide
March 22, 2023 - This means, they are more like suggestions. Variable names must start with a letter or an underscore _ character. Variable names can only contain letters, numbers, and underscores.
🌐
DEV Community
dev.to › bootdotdev › naming-variables-the-right-way-81a
Naming Variables the Right Way - DEV Community
April 10, 2021 - Here are some of my rules of thumb for high-quality variable nomenclature. Following existing naming conventions of the language or framework that you’re using · Single letter variables have a place, and that place is rare ... Different languages and frameworks (and the communities that use them) typically have a standard way of styling variable and function names. For example, in Python and Ruby it’s preferred to style variables and fields using snake case.
🌐
CodingNomads
codingnomads.com › python-variable-assignment-naming-convention
Assigning an Independent Variable is Easy
Following these rules when naming your variables is necessary to build a functional Python script: Your variable names can include numbers, but they can't start with a number.
🌐
Network Direction
networkdirection.net › home › python › python beginner › variables › variable conventions
Variable Naming Conventions in Python
December 23, 2021 - Python has variable naming conventions. That is, rules about how we should name our variables. This makes our code easier to read.
🌐
Log2Base2
log2base2.com › programming-language › python3 › basic › need-of-variables-in-python.html
Valid and invalid variable names in Python | Need of variables
1. Variable name should start with letter(a-zA-Z) or underscore (_). ... pass, break, continue.. etc are reserved for special meaning in Python.
🌐
W3Resource
w3resource.com › python-interview › what-are-variables-in-python-rules-for-naming-variables-in-python.php
Python variables: Definition, assignment, and naming rules
August 12, 2023 - Convention: Python is flexible ... and consistent. The convention is to use lowercase letters for variable names, with underscores (_) to separate words in multi-word variable names (snake_case)....
🌐
Python Land
python.land › home › variable naming
Variable naming • Python Land
April 2, 2024 - In my examples, I’ve picked the general name result, but you can choose any name you deem appropriate. As a general rule, always pick a variable name that best describes its contents. This practice makes your code more readable and easy to understand, not just for others, but also for future you.
🌐
Linode
linode.com › docs › guides › python-variables
Getting Started with Python Variables | Linode Docs
April 4, 2023 - Python variables support three popular naming conventions: Camel case, where the first letter is lowercase and each subsequent word in a name begins with an uppercase letter.
🌐
Quora
quora.com › What-is-the-best-practice-to-define-variable-name-in-Python
What is the best practice to define variable name in Python? - Quora
Answer (1 of 4): The best practice is to make it meaningful. So for instance if you are computing a total, use the variable name ‘total_of_ ’ rather than ‘total’ or ‘t’. (Where is what is being totalled). The only benefit to short variable names is that you have less typing...
🌐
Wikipedia
en.wikipedia.org › wiki › Naming_convention_(programming)
Naming convention (programming) - Wikipedia
5 days ago - In Python, if a name is intended to be "private", it is prefixed by one or two underscores. Private variables are enforced in Python only by convention. Names can also be suffixed with an underscore to prevent conflict with Python keywords. Prefixing with double underscores changes behaviour ...