Python Keywords and Identifiers (3rd part)

in Education5 years ago (edited)

Here I published the 3rd part of the consecutive series about Python Programming language to learn for all. Please check the previous parts.

Previous

Python Programming Language (1st part)
Variables Assignment In Python Programming Language (2nd part)

code-1084923_1280.png
Source

Each Programming language has its own syntax and structure . To define these syntaxes and structure reserved words are used. Python Programming language is no exception. There are 35 keywords in Python 3.8, each serving a different meaning for a different purpose.

Every keyword is a part of the vocabulary of the Python Programming language. So we can't use these keywords for defining names of variables, classes or functions.

Python keywords are case sensitive, which means they must be written as they are while we using them in our code.

To get the keywords list, open Python IDLE (windows) and type "help()" and hit enter. Type "keywords", voila! you can see now the whole python keywords list.

keywords1.JPG

We can also use Python's keyword module to get the list.

keywords2.JPG

To know about a specific keyword and its usage, type its name on the help mode and hit enter.

keywords3.JPG

Example of keyword :

Using “while” keyword we can run a loop in a code block for displaying the values of a variable.

 a = 12
 while a>3:
   print(a)
   a -= 1

Type on your Python IDLE and see.
Don't worry we will discuss details in the coming sections.
example1.JPG

Python Identifiers

When we assign a name to a variable, function, class, module or any other programmable entity, then it is called an identifier.

Python language has a set of rules to create identifiers.

Rules:

  1. A valid identifier can only have a combination of letters either in lowercase(a to z) or uppercase(A to Z) or digits(0 to 9) or underscore (__).
    num, num1, num_1, numTwo are valid identifiers example.
  2. The name of an identifier can't start with a digit. For example:
    1num is not a valid identifier name, but num1 is a valid one.
  3. Keywords can't be used as valid identifiers' names.
  4. Avoid special characters ['$', '%', '.', '@', '!' ] for naming a valid identifier.
  5. A valid identifier can have an unlimited length of the sequence of the characters.

we should aware that Python language is case sensitive. So, the identifier 'name' and 'Name' are not the same.
........................................

I hope that dear readers understand what has been discussed so far about today's topic.

Next

Python Data Types

Sort:  

I would consider adding the stem tag to one of the ones you use. I think the stem community here would love to see these types from you!

I have on my list of things to do soon, learn python. It’s pretty straight forward from what I hear. I tried to do c++ but it was brutal.

I’ll read up on your other ones!

Thanks for your attention and I'll follow your suggestion.