# What are the allowed characters in Python function names?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Python Identifiers

Identifier is the name given to entities like class, functions, variables etc. in Python. It helps in knowing one entity from another.

Rules for writing identifiers

Identifiers can be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore (_). Names like myClass, var_3 and print_to_screen, all are valid examples.

An identifier cannot start with a digit. 2variable is invalid, but variable2 is perfectly correct.

Keywords cannot be used as identifiers. The word ‘global’ is a keyword in python. So we get an invalid syntax error here

## Example

global = "syntex"
print global

## Output

File "identifiers1.py", line 3
global = "syntex"
^
SyntaxError: invalid syntax

Explanation:

The above code when run shows error because keyword global is used

as a variable/identifier for assigning a string value.

print $local ## Output File "identifiers2.py", line 1$local = 5
^
SyntaxError: invalid syntax

Explanation:

The above code when run shows error because special character \$ is used in the variable/identifier for assigning a integer value.

Updated on 12-Jun-2020 11:27:30