Python

Posted on at


My this Blog is related to Python,It is a programmimg language which we are going to use in Rasbeeri Pi.
Lets take start "How to get Python Software?"
So  My answer is that to get install python follow this link

http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html

Open this link and go for Python 2.7-x.Install this after downloading and then you have done then open it.
Go to start Menu and write python then select IDLE(Python GUI).


Now lets start discussion about the syntax of Python.It is very easy to learn and easy to use.When you open the Python a screen will be appear infront of you.
which is named as IDLE "Integrated Development Envoirnment".In this Enviornment you can write your programme.

Example 1: "Print"
If you want to print something you will used a command "print".
e.g: Hello TechDibba
write
>>>print "Hello TechDibba"
Hello TechDibba



Example 2: "Mathematics"
Now If you want to do a mathematical operation,then simply you can use (+,*,/,-,%) operations.
e.g: 2+2, 2-2, 2*2 ,2/2
write
>>>2+2
4
>>>2-2
0
>>>2*2
4
>>>2/2
1
>>>2%2
0
Note: If you want to multiply a single digit like 2 with itself like (2*2*2*2*2), then you can write simply 2**5.
>>>2**5
32

Note: In Math whenever we perform any operation it will follow maths rule like in addition and multiplication, first multiplication will be done.
and parenthesis have highest periority then others operation.

Example 3: "Comments"
This example is related to comment,In case somewhere we want to add something related to commands or anything else then how we can wrtie in Python.
so " # " is used to write comment in Python.
>>>print "TechDibba" #company name
TechDibba
>>>2/2 #Division
1


Example 4: "Variables"
Variables can store the values,which further can easily changesd without make a big change in all over the program.
lets take a example of it.
e.g" v is a variable which in which we want to store value 2,then simply we write
>>>v=2
2
>>>print "Value of v is" ,v
Value of v is 2
>>>print "Value of v",v," stored in v"
Value of v 2 stored in v

Example 5: "Strings"
Strings,which can strore texts.
e.g: I want to store a company name and its location and then want to print
>>>company="TechDibba"
>>>location="Islamabad"
>>>print company,location
TechDibba Islamabad
>>>print company+location
TechDibbaIslamabad
>>>print company+" "+location
TechDibba Islamabad

Example 6: "Loops"
Now we are moving towards loops,which are basically used to repeat a procedure more than one time.
While Loop
e.g:
>>>i=2
>>>while i<5:
i=i+1
print i

 

This is lesson one,second lesson will be uploaded after one or two days.So stay connected for further lessons.


TAGS:


About the author

Ihtasham-Zahid

I am student of Electronics Engineering in International Islamic University Islamabad.

Subscribe 0
160