Sunday, July 8, 2012


Hi Friends,

Here I am again  with you guys after a long time . Sorry for the delay, but i was caught up in office work for a long time and was extremely busy.

So, let us delve further into python, without waiting any further .


Think about arrays (feisty little boxes i call them) . Lists are very much like them . They can contain any and all types of variables and as many as you wish.

Consider this scenario :

We will declare a list first . Let's call it Klist .

Klist = [] ; //declaring a list

//Let's  build the  list


So the list now contains 3 elements A,B,C . 

Lets  print the elements inside the list now :

for i in Klist :
     print  i    // Prints  K, B C

Now beware . This  is  very important .

This list contains 3 elements . So if you  try to print an index, for which there is no element in the list .


print  Klist[12] ; // This  generates an error as, for  the index 12 , there is no element in the list .


All arithmetic operations are supported in python .
Addition, Subtraction , multiplication you name it , everything's there .

To return  remainder from a division you can use the modulo operator (%) .

To make a squared relationship , you can use double  * operators.

a = 7 ** 2 ; // that's actually  49

To concatenate strings  you can add them up .

kunalBhowmick = "Kunal" + "Bhowmick" ;

To concatenate a string multiple times :

Kstring =  kunalBhowmick * 10 ;

That makes  the list Kstring  contain 10 repetitive sequences of the string "kunalBhowmick " .

To join two lists you can use addition (+)  operator .

New lists can be made with a repeating sequence using the multiplication operator (*)  .

For example:

print  Klist * 3 ;

This prints the elements of the list Klist 3 times .

That's it friends for today . Next we will go through loops and conditions .

No comments:

Post a Comment