Download the python interpreter from this link . Choose either 3.0 or 2.0 version depending upon your compatibility. In this exercise version 2.0 was used for examples. Based on the current and future trends I would recommend 3.0.
Now let us look into some basic concepts in python programming language.
As with most programming languages, assigning a value for a variable is as simple as:
a = 10
The two switch states True or False can be assigned to a variable.
a = True
a = False
Reassigning variable values:
A variable b = 10 can be given a value as b = 5 in the next line, and the value can be printed using
Indentation is one of the most important aspect of python, either use a Tab space or 4 white spaces but not both. Here’s an example of a simple python function.
var = 15
Use # at the beginning of a line to give a single line comment.
# This is a single line comment in python.
If the comment is more than one line use double inverted comma’s thrice at the start and end of the comment.
“”” This is a multi-line
Basic Math Operations:
All basic math operations such as addition(+), subtraction(-), multiplication(*) and division(%) can be performed similar to other programming languages.
>>print 36 + 64
>>print 200 – 100
>>print 10 * 10
>>print 1000 / 10
In python, the function of exponential can be performed using ** keys.
>> chairs = 10 ** 2
>> print chairs
Modulo operation can be performed using %.
Assigning strings values and printing them.
python = “Hello world!”
In python both single quotes and double quotes can be used for commenting. When using single quote, the interpreter doesn’t understands the code. In such cases we can use escape characters such as backslash(\).
‘Isn\’t it the python?’
Accessing by Index:
We can access any character of a string by indexing. Indexing starts from 0.
>>sixth_letter = “python”
We can calculate length of the string using len()
>>python = “Indian”
We can convert lower case string to upper case string
>>python = “indian”
We can convert upper case string to lower case string
>>python = “INDIAN”
We can convert a variable to a string
>>pi = 3.14
So, this concludes basics of python part-1.