With Python 3.8 one can simply use f-string debugging feature:

>>> foo = dict()
>>> f'{foo=}'.split('=')[0]
'foo' 

One drawback of this method is that in order to get 'foo' printed you have to add f'{foo=}' yourself. In other words, you already have to know the name of the variable. In other words, the above code snippet is exactly the same as just

>>> 'foo'
Answer from Aivar Paalberg on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_variables_names.asp
Python - Variable Names
... myvar = "John" my_var = "John" _my_var = "John" myVar = "John" MYVAR = "John" myvar2 = "John" Try it Yourself » ... Variable names with more than one word can be difficult to read.
🌐
Real Python
realpython.com › python-variables
Variables in Python: Usage and Best Practices – Real Python
January 12, 2025 - These variables follow the rules for creating valid variable names in Python. They also follow best naming practices, which you’ll learn about in the next section. The variable name below doesn’t follow the rules: ... >>> 1099_filed = False File "<input>", line 1 1099_filed = False ^ SyntaxError: invalid decimal literal · The variable name in this example starts with a number, which isn’t allowed in Python.
Discussions

python - Getting the name of a variable as a string - Stack Overflow
For example, suppose you have: my_dict = {'n_jobs': ..., 'users': ...}. Then you can use my_dict['n_jobs'] in lieu of n_jobs. Anyway, what matters to me is that I only need to type "n_jobs" once, either as a var name or as a string in the dict key. ... Variables don't "have names"; "variable" means the same thing as "name" in Python... More on stackoverflow.com
🌐 stackoverflow.com
Dynamic variable name
Suppose i have to set q_variable = 0 a_variable = 0 def stats(choice): choice + '_variable' += 1 stats('q') Here after adding the choice + ‘_variable’ will become string. If i want to change the q_variable or the a_variable depending on the choice we provide to the function. How do we do that? More on discuss.python.org
🌐 discuss.python.org
10
1
August 30, 2022
Follow these rules to write PYTHON variables names like a PRO.
You SHOULD separate words with underscores and not spaces. I'll keep using spaces. Works great so far. More on reddit.com
🌐 r/Python
9
0
September 20, 2022
How do i display the variable's name instead of it's value
Look into dictionaries More on reddit.com
🌐 r/learnpython
42
16
November 16, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-variables
Python Variables - GeeksforGeeks
Avoid using Python keywords like if, else, for as variable names. ... 1name = "Error" # Starts with a digit class = 10 # 'class' is a reserved keyword user-name = "Doe" # Contains a hyphen · Basic Assignment: Variables in Python are assigned values using the = operator.
Published   3 weeks ago
🌐
Python
peps.python.org › pep-0008
PEP 8 – Style Guide for Python Code | peps.python.org
Note: there is some controversy about the use of __names (see below). Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL. Always decide whether a class’s methods and instance variables ...
🌐
Tutorial Teacher
tutorialsteacher.com › python › python-variables
Python Variables: A Beginner's Guide to Declaring, Assigning, and Naming Variables in Python
Just assign a value to a variable using the = operator e.g. variable_name = value. That's it. The following creates a variable with the integer value. ... In the above example, we declared a variable named num and assigned an integer value 10 to it.
🌐
W3Schools
w3schools.com › python › python_variables.asp
Python Variables
Variable names are case-sensitive. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Find elsewhere
🌐
Runestone Academy
runestone.academy › ns › books › published › py4e-int › variables › variable-names-keywords.html
2.3. Variable names and keywords — Python for Everybody - Interactive
The variable name 76trombones is illegal because it begins with a number. The name more@ is illegal because it contains an illegal character, @. But what’s wrong with class? It turns out that class is one of Python’s keywords. The interpreter uses keywords to recognize the structure of ...
🌐
GoPa
faun.dev › co › stories › realbenjizo › a-beginners-guide-to-variables-in-python
A Beginner’s Guide to Variables in Python
November 24, 2021 - When naming a class, Python recommends starting each word with a capital letter. If you are using two words in your variable name, do not separate the words with an underscore, start both words with capital letters without space between them. This style is called Camel Case. See the example below of a class variable called last names.
🌐
Log2Base2
log2base2.com › programming-language › python3 › basic › need-of-variables-in-python.html
Valid and invalid variable names in Python | Need of variables
So, it will be very easy to make use of the memory address using a variable name rather than hexadecimal values. In the above diagram, memory address 22fe4c has been mapped with the variable name letter.
🌐
BeginnersBook
beginnersbook.com › 2019 › 03 › python-variables
Python Variables with examples
Variable name is known as identifier. There are few rules that you have to follow while naming the variables in Python. 1. The name of the variable must always start with either a letter or an underscore (_). For example: _str, str, num, _num are all valid name for the variables.
🌐
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

🌐
Geo-python
geo-python.github.io › site › notebooks › L1 › gcp-1-variable-naming.html
Good coding practices - Selecting “good” variable names — Geo-Python site documentation
August 19, 2020 - Again, if we consider the examples from the previous section, we might consider the variable name fmiStationID or simply stationID if we elect to use camelCase. As mentioned in point 1, pothole_case_naming is preferred, mostly because we feel it is the easiest to read and seems to be most common amongst Python programmers.
🌐
Mimo
mimo.org › glossary › python › variables
Python Variables: Essential Concepts & Best Practices
Snake-case names start with a letter or underscore followed by letters, underscores, or numbers. As examples, consider base_salary and experience_multiplier. In Python, variable names are case-sensitive, which means base_salary and BASE_SALARY are two different variable names.
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Python Variables and Assignment | Pluralsight
September 26, 2018 - Variable names may not be a reserved word in Python. Following the rules above, all of these variable assignments are legal: >>> fish = 11 >>> a = 12 >>> _wow_ = 13 >>> a1 = 14 >>> something_longer_is_fine_2 = 15 >>> RemoteAddress = '10.20.30.40' All the above variable names are acceptable. But just because they are acceptable does not mean you should use them. The Python community has further developed naming conventions which should be followed. For example, even though a single-character identifier is perfectly legal, you are strongly discouraged from using the characters l (lower case el) or O (uppercase oh) or I (uppercase eye).
🌐
freeCodeCamp
freecodecamp.org › news › python-variables
Python Variables – The Complete Beginner's Guide
March 22, 2023 - For example, a variable named "site name" should be written as "sitename"._ This convention is called snake case (very fitting for the "Python" language).
🌐
Apmonitor
apmonitor.com › che263 › index.php › Main › PythonBasics
Python Programming Basics
Each Python object has defining properties including the Identity (a memory address), Type (e.g. string, integer, floating point number), and Value. Below is an example of assigning 'x' as an Integer and printing the object properties. x=2 # create variable 'x' print(x) # print value => 2 print(id(x)) # print id number => 1737348944 print(type(x)) # print type => <class 'int'>
🌐
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. exampleVariable = "This is a string variable." anotherExampleVariable = 31