Keywords and Identifiers in Python

Keywords and Identifiers in Python: 

Keyword is a reserved word in Python that has special meaning and can not be used as an identifier.These unique words are used to define the syntax and the structure of the Python language. Whereas, the names given to variables, functions, classes, etc., are identifiers. 

keywords and identifiers in Python

Keywords and Identifiers in Python

Keywords and Identifies are two fundamental aspects of python programming language that make it incredibly coder friendly, which will help you understand why you should learn it.

keywords and identifiers in Python

Keywords in Python :

A Python keyword is a special reserved word that has specific meaning and purpose, and can only be used in the context of its specific meaning and purpose.

All Keywords in Python are in lower case but some keywords like True, False etc are in uppercase. So, We can say that Python can have keywords as lowercase, uppercase as well as Capitalized.

Common Keywords used in Python:

  • if
  • else
  • for
  • True
  • False
  • break
  • pass
  • continue

Example of Keywords:

Run
me='Xyz'
if(me=='Prepster'): 
    print('Welcome to PrepInsta') 
else : 
    print('You are welcome to become a Prepster.')
Output :

You are welcome to become a Prepster.

Identifiers in Python: 

An identifier is a name assigned to an entity, such as a variable, class, function, etc. By identifying entities in code, it is easier to understand their flow and differentiate them from each other.

There are some rules for identifiers in python:

  • All identifiers must begin with a letter (a-z, A-Z) or an underscore (_).
  • The rest of the identifier can contain letters, digits (0-9), and underscores.
  • Identifiers are case-sensitive, meaning myVar and myvar are treated as different identifiers.
  • In order to make your code more readable, you should name your identifiers descriptively and meaningfully.
  • In Python, An Identifier can have a maximum length of 79 characters.

Valid identifier: abc123

Invalid identifier: 123abc

Example of Identifiers:

Run
my1 = "Prepinsta"
print(my1)
Output:
Prepinsta
Run
1my = "Prepinsta"
print(1my)
Output:
File "/home/main.py", line 3
1my = "prep"
^
SyntaxError: invalid decimal literal

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription