What are the allowed characters in Python function names? Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 6 Likes Like Report The user-defined names that are given to Functions or variables are known as Identifiers. It helps in differentiating one entity from another and also serves as a definition of the use of that entity sometimes. As in every programming language, there are some restrictions/ limitations for Identifiers. So, is the case with Python, we need to take care of the following points before using an Identifier. Rules for writing Identifiers: The first and foremost restriction is that Identifiers cannot be the same as Keywords. There are special reserved keywords in every programming language that has its own meaning and these names can't be used as Identifiers in Python. Python3 # Python program to demonstrate # that keywords cant be used as # identifiers def calculate_sum(a, b): return a + b x = 2 y = 5 print(calculate_sum(x,y)) # def and if is a keyword, so # this would give invalid # syntax error def = 12 if = 2 print(calculate_sum(def, if)) Output: File "/home/9efd6943df820475cf5bc74fc4fcc3aa.py", line 15 def = 12 ^ SyntaxError: invalid syntaxAn identifier in Python cannot use any special symbols like !, @, #, $, % etc. Python3 # Python code to demonstrate # that we can't use special # character like !,@,#,$,%.etc # as identifier # valid identifier var1 = 46 var2 = 23 print(var1 * var2) # invalid identifier, # will give invalid syntax error var@ = 12 $var = 55 print(var@ * $var) # even function names can't # have special characters def my_function%(): print('This is a function with invalid identifier') my_function%() Output: File "/home/3ae3b1299ee9c1c04566e45e98b13791.py", line 13 var@ = 12 ^ SyntaxError: invalid syntaxApart from these restrictions, Python allows Identifiers to be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore (_). But variable name must not be started with digits. Names like myClass, var_3, and print_to_screen, are valid examples. Python3 # Python program to demonstrate # some examples of valid identifiers var1 = 101 ABC = "This is a string" fr12 = 20 x_y = 'GfG' slp__72 = ' QWERTY' print(var1 * fr12) print(ABC + slp__72) Output: 2020 This is a string QWERTY Create Quiz Comment E equbalzeeshan Follow 6 Improve E equbalzeeshan Follow 6 Improve Article Tags : Python Python-Functions Python function-programs Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like