Python Forum
How long can an identifier be in Python? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: How long can an identifier be in Python? (/thread-14444.html)



How long can an identifier be in Python? - himanibansal - Nov-30-2018

What is the usual length of a python identifier? Are there any rules regarding it?


RE: How long can an identifier be in Python? - DeaD_EyE - Nov-30-2018

Guessing: Your memory limits the length of a name.


RE: How long can an identifier be in Python? - dukoolsharma - Dec-01-2018

In Python, an identifier can be of any length. Apart from that, there are certain rules we must follow to name one:

*It can only begin with an underscore or a character from- A-Z or a-z.
*The rest of it can contain anything from the following: A-Z/a-z/_/0-9.
*Python is case-sensitive, as we discussed in the previous question.
*Keywords cannot be used as identifiers. Python has the following keywords:
and, def, False, import, not, True,
as, del, finally, in, or, try,
assert, elif, for, is, pass, while,
break, else, from, lambda, print, with,
class, except, global, None, raise, yield,
continue, exec, if, nonlocal, return,


RE: How long can an identifier be in Python? - Mekire - Dec-02-2018

So, we can make all the SingletonAbstractAbstractFactoryFactories we want but um... let's not.


RE: How long can an identifier be in Python? - Gribouillis - Dec-02-2018

I just tried a 10MB name and there was no problem. Only a small delay in the compiling step
>>> name = "a" * 100000000
>>> assign = "{} = 3".format(name)
>>> exec(assign)
>>> print(eval(name))
3



RE: How long can an identifier be in Python? - ichabod801 - Dec-02-2018

Reminds me of working in SAS, which has (at least until recently) a limit of 32 character names. I was also using an SQL database made by people who liked to make really long names instead of documenting anything, like ClericalCodingCompleteDateTime which has 33 characters. Although the latest version they installed, right before I left that job, allowed names with spaces in them. IIRC, the catch was that you had to quote them and precede it with an n. So n'credit card' was a valid variable name.