Метод строки isidentifier() поможет узнать, подходит ли данная строка в качестве имени объекта.
Вполне может заменить самостоятельно придуманную регулярку.
>>> 'some_name'.isidentifier()
True
Обычное имя переменной
>>> '私は手紙です'.isidentifier()
True
Юникод в качестве имени тоже доступен
>>> '1_name'.isidentifier()
False
Имя не может начинаться с цифры
>>> '੬_name'.isidentifier()
False
Включая все цифры юникода
>>> 'some name'.isidentifier()
False
Пробелы недопустимы
#basic
🪐 In 1976, NASA’s Viking 1 lander touched down on Mars and conducted the first experiments specifically designed to search for signs of life on another planet. The Viking lander analyzed Martian soil for chemical reactions that might indicate life, and while some results were intriguing, no definitive evidence of Martian microbes was found, keeping the mystery of aliens alive on the Red Planet. ✨
#Mars⚡#Viking⚡#extraterrestrial⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries