Keywords & Identifiers in Python

Keywords & Identifiers in Python

Let's write comments as well

Namaste Coders!

In this article, we will learn about what are identifiers and keywords in Python. Let's discuss comments in bonus section.

Keywords

Keywords are “reserved words” that convey a special meaning to the interpreter. Keywords cannot be used as a variable name in the program snippet.

11.PNG

It’s hard to remember all the keywords. Thus, we can get a list of all keywords by following.

12.PNG

Identifiers

An identifier is a name given to entities like classes, functions, variables, etc. It helps to differentiate one entity from another. Identifiers cannot be named as keywords as it will throw an error.

Rules for writing Identifiers:

  • It is a combination of alphabets[a-z, A-Z] , digits[0-9] and only underscore(_) as a special symbol
  • Never begin with a digit
  • Do not contain spaces
  • Reserved words cannot be used
  • These are case-sensitive

13.PNG

Statements

These are the instructions that are executed by the python interpreter. For example, num=2 is an assignment statement. if statement, for statement, while statement, etc. are other kinds of statements that will be discussed later.

14.PNG

Multiline Statements

In Python, the end of a statement is marked by a newline character. But we can make a statement extend over multiple lines with the line continuation character ().

15.PNG

Comments

Comments are statements in the python program which are not interpreted i.e, these are ignored by the interpreter. Comments are used for debugging purposes. Also, it helps you to write what that particular code is performing even if a third person views the code, he also gets the idea about the program. Writing comments comes under good programming practices.

Single Line Comment

#(pound sign) is used in python for comments

16.PNG

Multiline Comments

“”” “”” (triple quotes) are used in python for multi line comments

17.PNG

The End

I hope you enjoyed the article and had a good learning experience.

Follow for more articles and keep sharing👩

Keep coding

Linkedin

hashnode blogs

Did you find this article valuable?

Support akshita garg by becoming a sponsor. Any amount is appreciated!