Getting started with PYTHON!!! #2.1 - Identifiers , Keywords & Literals

Getting started with PYTHON!!! 
#2.1 - Identifiers , Keywords & Literals

Hello People, in my previous blog I talked about python programming language a bit , let's dive deeper into the PYTHON WORLD .

So, before talking about identifiers , let's talk about something which we learnt in our primary classes , i.e. , variables. What comes to your mind when you hear the term variables ? The first thing that I think about variable is that it is an alphabet which is used to store some data or value , for eg: x=5 , here x is a variable which has a value of 5. Similarly, identifier is a name given for some data .

Now let's talk about keywords. If we say Biriyani your mouth starts watering right ? By Biriyani, we mean a special rice dish . Similarly, keywords are some special words in python which have a pre-defined meaning.

When we talk about literals , it's the value or data that we give to a identifier. Unless and until we write a=5, the data 5 remains unnamed . so 5(unnamed data) here is known as literal.

IDENTIFIER : It is a name given for some data , to identify a variable, function, class or other modules.

x=5
print(x)

KEYWORD : Keywords are the reserved words which have pre-defined meaning in python.

global x=10    #global is a keyword here , this line signifies that x is a global variable.
print(x)

LITERAL : Literals are data which is assigned to some variable or constants.

n=5     #5 is numeric literal
f=1.2     #1.2 is a floating literal
c="a"     #a is a character literal
s="Soham"    #Soham is a string literal
b=True   #True is a boolean literal and True has a value of 1 whereas False has a value of 0 .

NOTE :

always try to use the Print statement to debug your code to understand clearly how is the code being implemented , whenever you can't find logic behind something or why the code isn't working ,try to print the variable in that line and check if the value is the desired value that you want before proceeding on the next statement. For example :

b=True
c=5+b
print("c=",c)

output c=6

You may be confused as how how come c comes out to be 6,then try using the print statement for the value of b as shown in the code below and then every will be crystal clear.

b=True
print(b)    #since True has a value of 1 therefore 5+b=5+1=6
c=5+b
print("c=",c)

RULES for writting a identifier :

  • It can be combination of letters(either in uppercase or lowercase) or numbers or underscore

    aB12__

  • An identifier cannot start with a number.

    1number ❌
    number1 ✅

  • We cannot use special symbols like !, @, #, $, % etc. in our identifier.

    @ = 5 ❌

  • Keywords cannot be used as identifiers.

    global=7 ❌

ONLINE COMPILER

You must know this :

Python is a case-sensitive language . Therefore, identifier and IDENTIFIER are different.

Try to define identifiers which makes sense so that later when you view your code you can actually relate to what you actually meant when you defined the identifier earlier . In the second code you can easily understand that the identifier count has been used to count the number of balls.

b=["blue","green"]
c=len(b)
print(c)
balls=["blue","green"]
count=len(balls)
print(count)