There's this guy here who insists that python variables can be assigned like
1 = 'foo'
I need help on what to tell him.
There's this guy here who insists that python variables can be assigned like
1 = 'foo'
I need help on what to tell him.
No.
A variable name must start with a letter or the underscore character.
A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z
, 0-9
, and _
)
No it cannot haha. the simplest way to tell him is to show it.
if you run the code
1 = 'foo'
then you will get an error message, that will help him understand.
File "<stdin>", line 1
SyntaxError: can't assign to literal
You can't do that. You get a syntax error.
Also, per PEP8:
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.
It is impossible.
Name of variable in python should not be started with any number.
You can't use digits as the first character of a name. See https://docs.python.org/3/reference/lexical_analysis.html#identifiers