python basics 01

Upload: mohammed-sarjoon

Post on 08-Jan-2016

215 views

Category:

Documents


0 download

DESCRIPTION

use full

TRANSCRIPT

Python Basics 01Table of Content

Pythonis veryeasy to useand it can be used for arithmetic operations. in this section lets look how we can usepythonas acalculator. This section is described threesections.

PythonBasics01 :-PythonOpreratorsPythonBasics02 :-PythonData types, Variables and otherbasics(This will be discussed in next section)Python Basics 01 :- Python OperatorsAn operator is asymbolthat is used for calculations. In simple 3 + 5 3 and 5 are operands and+is the operator.Pythonlanguage supports following type ofoperators. ArithmeticOperators Comparision Operators Logical (or Relational)Operators AssignmentOperators Conditional (or ternary) Operators

Python Arithmetic Operators

OperatorDescriptionExample

+Addition - Adds values on either side of the operatora + b will give 30

-Subtraction - Subtracts right hand operand from left hand operanda - b will give -10

*Multiplication- Multiplies values on either side of the operatora * b will give 200

/Division - Divides left hand operand by right hand operandb / a will give 2

%Modulus - Divides left hand operand by right hand operand and returns remainderb % a will give 0

**Exponent - Performsexponential(power) calculation onoperatorsa**b will give 10 to the power 20

//Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed.9//2 is equal to 4 and 9.0//2.0 is equal to 4.0

Now let's see some examples inpythonIDE. (click here to see how the python GUI is opened)

Here after I will not put anyscreen shotsof the GUI. I will put only the code as follows.>>>2 + 35>>>3 - 12>>>2 * 510Python Comparison Operators

OperatorDescriptionExample

==Checks if the value of two operands are equal or not, if yes then condition becomes true.(a == b) is not true.

!=Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.(a != b) is true.

Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.(a b) is true. This is similar to != operator.

>Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.(a > b) is not true.

=Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.(a >= b) is not true.