Keywords, Identifiers, Variables , comments & Identity

                             Python Keywords

There are several reserved Keywords in python which cannot be used as variable or identifier in python

These keywords has same definite purpose and are case sensitive ..



We will discuss about these keywords later in due course ...

                                      Identifiers 

Identifiers are name used identify the variables 

It cannot be keywords because keywords are reserved for special purpose

Identifiers can start with lower case , UPPER CASE, __ underscore but cannot be special character..

Example : router = "ASR 1k"

Here router is Identifier , now ASR 1k is inside double quotes hence router is consider as a string variable.



1
2
3
4
>>> router = "ASR 1K"
>>> type(router)
<class 'str'>
>>> 



Explanation :
Here, router is Identifier 
ASR 1K is string written inside 2 double quotes
String is assigned to identifier , hence router considered as string variable
So when we issued type syntax to know more type of data types (explained later), it given output as String data type...

                                 Variables 

It refers to object or identifier which has stored object or values in memory 
Variable can string , numbers, alphanumeric etc ... 
Unlike C/C++ we do not need to specifically define type of variables like Integers or strings
In other words,  in Python when we assign an integer to variable it became int variable & when we assign string to variable it became string variable 


>>> number = 123
>>> type(number)
<class 'int'>
>>> 
>>> word = "123"
>>> type(word)
<class 'str'>
>>> 


So in above example number variable is int variable because integer is assigned , similarly 
word is string variable because string is assigned , please note anything you write inside double " " or ' ' single quote it is considered as string ...


                                Comments 


While writing the code it is good habit  to document the purpose of code , this will help us debugging or understanding the code in later stage...

Comment on code doesnt get executed by compiler & so you can use this comment feature to strike out any code without deleting it from program, for example below router = "ASR 1K" is valid syntax but compiler will ignore it because it considered as comment as # is used at the start of syntax...

It always starts with #


                        Identity & Objects

Every object in Python is assigned a unique identity (ID) which remains the same for the lifetime of that object.

For example 10 is integer in memory it is located at 4497108256 so , when we assign x variable with 10 , x is started pointing to same location in memory i.e 4497108256

Thats the identity (4497108256) of object (x or 10)

id () is syntax is find the identity or memory location of any object .... 


Comments

Popular posts from this blog

How to Configure SIG Tunnel using vManage for SDWAN

Mutable & Immutable Data Types