Home Python Keywords
Post
Cancel

Python Keywords

Python Keywords and Identifiers

This tutorial will teach you about keywords, which are the reserved words in Python, and learning about identifiers which are variables and functions. Python Keywords

Keywords are the words that are reserved by Python.

They are used to define the syntax and the structure of Python.

Python keywords are case sensitive.

All but three of the keywords are lowercase. The three upper-case words are True, False, and None. Here is a list of all the keywords. Do not worry about remembering them all, you will learn them over time.

and as assert async await
break class continue def del
elif else except False finally
for from global if import
in is lambda None nonlocal
not or pass raise return
True try While with yield
elif else      

Python Identifiers

An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one thing from another in your code. Rules for writing your identifiers

  1. Your identifiers can be a combination of of letters in lower or upper case a-z and A-Z, digits 0-9, and even an underscore _ as well! gasp!

  2. Some examples of what you can name your identifiers: myVariable, var_1, and This_can_also_be_an_identifier3000 are valid.

  3. Your identifiers can not start with numbers. So no 2020sucks. Though covid-19 does work.

  4. As mentioned before, keywords can not be used as an identifier.

global = 1

Output

File "Method.py", line 1
    global = 1
           ^
SyntaxError: invalid syntax
  1. We also can not use special characters like: !, @, #, $, % etc in our identifier.
var! = 1

Output

File "Method.py", line 1
    var! = 1
       ^
SyntaxError: invalid syntax

Some useful tips

Python is a case sensitive programming language which means myVariable and MyVariable are not the same.

Identifiers can be of any length but it is good practice to use meaningful names. So an example is if you wanted a counter you would not call it w = 40 instead you would want counter = 40. This allows you to know what they are when you have to come back and read your code later when you do not remember what you wrote.

This post is licensed under CC BY 4.0 by the author.