Basic programming in Python:

Basic programming in Python:

For writing programs in Python we can use IDLE (Python GUI) or Python (command line).

Opening IDLE (Python GUI)tool for writing python codes:

Go to the start menu –> search for Python –> Click on IDEL (Python GUI)

IDEL stands for (Python GUI) Integrated Development Environment.

And for starting Python (command line) follow as below:

Go to the start menu –> search for Python –> Click on Python (command line)

Let us start with a very simple program by printing “Hello Sloba”

Below figure shows how to run Python codes on Python (command line):

clip_image002

Below figure shows how to run Python codes on IDEL (Python GUI):

clip_image004

Now let us see how we can do math on Python.

For doing this we need to know few basic commands like Addition (command is used by ‘+’ sign) ,Subtraction ( ‘- ‘ sign ), Multiplication ( ‘ * ‘ sign ), Division ( ‘ / ‘ sign ) , Remainder (can be used by ‘ % ‘ sign ) , Exponent (with ‘ ** ‘ sign) .

We should also remember that the math rules (order of operation) also applicable in Python too:

1) Parentheses (): When this is there then it will be first executed or will compute at first

2) Exponents **: will be the second

3) Hierarchically starts with multiplication *, division \, and remainder %

4) First addition + and then subtraction – .

For example:

clip_image006

Here in the above figure we can see that without using the parentheses Python chooses the basic math rule but whenever we use parentheses then that piece of code get calculated first.

As from the above mentioned calculation we can see the difference in the result i.e. 1 and 6.

Another most important part of any codes that we write is comments, it is always important whenever we start writing any scripts or a piece of code. We can have the information like who has developed the code on what date, like why this code is used and mostly used for providing information to another programmer like for why the code is been used. This can be represented by hash symbol ( # ).

For example:

clip_image008

From the above we can see how we can use comments while programming in Python.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s