Post

Python Keywords and Identifiers

This tutorial will teach about keywords and identifiers, which will include reserved words in python.

Python Keywords and Identifiers

Python Keywords

Python keywords are the python reserved words reserved by python language secured to define the python syntax and structure of the python language. We cannot use these reserved keywords as variable names, function names, class names, or other identifiers. In python, all the keywords are case-sensitive. All the python keywords should contain lowercase letters only except True, False, and None must be written as they are.

The following list shows the keywords in python.

KeywordDescription
TrueThis keyword represents the Boolean Value ‘true.’
FalseThis keyword represents the Boolean Value ‘false.’
NoneThis keyword represents the Null Value
andThis is a logical operator
asThis keyword used for creating an alias
assertThe assert keyword is used to insert debugging assertions in the program.
asyncThis keyword is always used in the coroutine function body.
awaitThis keyword is used for asynchronous processing.
breakThis keyword is used to break the loop.
classThis keyword is used to define a class.
continueThis keyword is used to take the control back to the loop.
defThis keyword is used to define a function.
delThis keyword is used to delete objects like variables, lists, or any other kind of object.
ElifThis keyword is used for a conditional statement along with an if statement.
elseThis keyword is also used as a conditional statement, the same as above.
exceptThis keyword is used for exceptional handling in Python.
finallyThis keyword is used for exceptional handling, but finally, the block will always get executed.
forThis keyword is used as a looping statement used to iterate over the elements of a sequence.
fromThis keyword is used to import a function in python.
globalThis keyword is used to declare global variables.
ifThis keyword is used to declare a condition in Python.
importThis keyword is used for importing the module in python.
inThis keyword is used to check specific values are present in an iterable object.
isThis keyword is used to test object identity
lambdaThis keyword is used to make anonymous functions.
nonlocalThis keyword is used to access the variables defined outside of the scope in the block.
notThis keyword is used to negates a Boolean value.
orThis keyword is used for a conditional statement where at least one condition must be fulfilled.
passThis keyword is used to tell the program or a function to do nothing.
raiseThis keyword is used to create a user define exception.
returnThis keyword is used to return a value at the time function is exited
tryThis keyword is used to specifies the exception handlers.
whileThis keyword is used to run a block of statements till the expression is fulfilled
withThis keyword is used to open a file.
yieldThis keyword is a replacement for a return keyword.

At first, this keyword will look very difficult to understand but believe me, all the keywords will make sense once we continue with our python tutorial, and if your want to learn in-depth about keywords with examples, you can see this (Link to another page for keywords in details)

To see the latest list of python keywords, we can follow the following steps.

Step 1: Open Python IDLE or Python Interpreter

Step 2: type the help() command to access the help shell.
Step 3: type keywords on the help shell, and you will get the following result.

Python Identifiers

What are identifiers in python?

The identifiers in python are a name used to identify a variable, function, class, module, or other objects. An identifier follows specific python rules that can combine an uppercase letter from A - Z or a lowercase a - z. It can also start with an underscore(_) followed by any number from 0 - 9 or letter.
Example a_data, a1, This_is_variable, and v_3 all are valid identifiers.

An identifier like 1name is invalid, and it cannot start with a digit. Also, keywords cannot be used as identifiers.

Python identifiers examples

Lets us see some examples of valid and invalid identifiers in python

Below are the list of valid python identifiers.

  • abc123
  • abc_de
  • _abc
  • ABC
  • abc

Below is the examples of invalid identifiers in python.

  • 123abc
  • abc@
  • 123
  • for

FAQ

Question: Are python variable case sensitive?
Answers: Yes, the Python variable is case sensitive; both “Python” and “python” are different in a python programming language.

Question:Is python case sensitive when dealing with identifiers?
Answers:Yes, Python is case-sensitive when we are dealing with identifiers.

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