Python Forum
How long can an identifier be in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How long can an identifier be in Python?
#1
What is the usual length of a python identifier? Are there any rules regarding it?
Reply
#2
Guessing: Your memory limits the length of a name.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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,
Reply
#4
So, we can make all the SingletonAbstractAbstractFactoryFactories we want but um... let's not.
Reply
#5
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
Reply
#6
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020