- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the allowed characters in Python function names?
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
global = "syntex" print global
File "identifiers1.py", line 3 global = "syntex" ^ SyntaxError: invalid syntax
The above code when run shows error because keyword global is used
as a variable/identifier for assigning a string value.
We cannot use special symbols like !, @, #, $, % etc. in our identifier.
$local = 5 print $local
File "identifiers2.py", line 1 $local = 5 ^ SyntaxError: invalid syntax
The above code when run shows error because special character $ is used in the variable/identifier for assigning a integer value.
- Which characters are NOT allowed in MongoDB field names?
- References are not allowed in a SAP remote function call
- What are the different time format characters used by MySQL DATE_FORMAT() function?
- What are Python function attributes?
- What are the modifiers allowed for methods in an Interface in java?
- What are different date format characters used by MySQL DATE_FORMAT() function?
- What are the modifiers allowed to use along with local variables in Java?
- How to limit the number of characters allowed in form input text field?
- Are static local variables allowed in Java?
- How do we add the maximum number of characters allowed in an element in HTML?
- Check if a string has all characters with same frequency with one variation allowed in Python
- What are required arguments of a function in python?
- How to use special characters in column names with MySQL?
- How to get a list of parameter names inside Python function?