This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: variable naming
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: kaiser, ned.deily, steven.daprano
Priority: normal Keywords:

Created on 2015-04-19 09:43 by kaiser, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bugs.py kaiser, 2015-04-19 09:43
Messages (3)
msg241502 - (view) Author: john kaiser (kaiser) Date: 2015-04-19 09:43
found error when naming variables with basic functions

how to replicate

while=123 #while should be treated as variable name
while True: #this should be treated as a function
	print while #this should be as a variable name

result:
  File "C:\Users\_you got served_\Desktop\bugs.py", line 1
    while = 123
          ^
SyntaxError: invalid syntax
msg241505 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-04-19 10:10
This is not a bug. "while" is a keyword, it is part of Python's syntax, and you are not permitted to use keywords as variable names. This is not an accident, but a deliberate decision.
msg241549 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-04-19 19:21
(... and is documented in The Python 3 and 2 Language Reference manuals: https://docs.python.org/3/reference/lexical_analysis.html#keywords and https://docs.python.org/2/reference/lexical_analysis.html#keywords)
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68191
2015-04-19 19:21:52ned.deilysetnosy: + ned.deily
messages: + msg241549
2015-04-19 18:40:20zach.waresetstage: resolved
2015-04-19 10:10:19steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg241505

resolution: not a bug
2015-04-19 09:43:09kaisercreate