Wednesday, May 23, 2012

STEPPING INTO PYTHON - CHAPTER 1

Hi friends,

This is the first chapter in the stepping into python series. This series will be updated from point of view of the beginners and gradually more advanced features will be published .
So without any further ado, let us delve into the language at hand .

 How to install Python :

FOR WINDOWS USERS : There are a lot of  python interpreters available. Download them and get started. However i vehemently oppose it. Python is a free software available in Linux. So download any flavor of Linux and  get started(My personal favorite is Ubuntu).

FOR LINUX USERS : Just type python in your shell and the interactive mode opens and you are good to go .

OOP : Python is an object oriented language and any variable that you use here acts as an individual object .

SOME IMPORTANT TID BITS :
                                                     help(obj) --> this gives you info on the object
                                                     dir(obj)   --> this gives you the internal structure of the object being used .

BASIC VARIABLES :

INTEGER : An integer is defined in this way :
                   kint = 8
FLOATING POINT NUMBER : kfloat = 7.0

STRINGS : When it comes to strings, you can use single quotes and double quotes both .
kstring = 'kunal'  //valid
    or
kstring = "kunal" //valid

Note double quotes are useful when you are using a string with a single quote in it .

kstring = 'kunal's not home .' // Not valid

This is not valid because the single quote which is there at the beginning of the string in 'k'  ends when it  encounters the single quote after 'l' , hence you have another single quote after stop(.) which is unaccounted for and hence the termination of the string will take place at a time much before than actually expected .

So we use double quotes in such situations :

kstring = "kunal's not home ." // valid

Concatenation  and simple operation is very easy in python :

five = 5
ten = 10

fifteen = five + ten


Hi = "hi"

Ganesh = "ganesh"
HiGanesh =Hi + Ganesh

ASSIGNMENTS :

Assignment can be done in more than one variable and in the same line .

a=2,b=3

BEWARE :

But  for all this cool tricks, do not forget one important thing .
DON'T MIX YOUR OPERATORS OR IT WILL BE THE DEATH OF YOU .

print  five + Hi  // Not Valid --> don't try to concatenate a number with a string .

That is all for today, next we will be looking into chapter 2 of this series which will deal with lists and operators .

Goodbye to you,

All the free thinking souls .


3 comments:

  1. Nice initiative...
    I'm following this closely...

    ReplyDelete
  2. Good start Kunal, looking forward to more. Keep them coming.

    One more cool thing I liked about pythong was this statement

    a,b = 2,3 this is equivalent to a=2, b=3

    ReplyDelete