VASUNDHARA, SEC-1
GETTING STARTED WITH PYTHON
UNIT 2 – GETTING STARTED WITH PYTHON
Points to Remember :
Python was developed by Guido van Rossum at the National Research Institute for Mathematics and
Computer Science in the Netherlands.
Python is a widely used general-purpose, high-level programming language.
Python is free to use, even for commercial products, because of its OSI-approved open source license.
Python is strongly object-oriented in the sense that everything is an object including numbers, strings and
functions.
Python Supports interactive mode in which you can enter results from a terminal right to the language,
allowing interactive testing and debugging of snippets of code.
In script mode, we type the programs in a file and then use the interpreter to execute the contents of the file.
PyScripter is a full-featured stand- alone Python IDE with Integrated Interpreter, debugger , Syntax Error
Highlighting and many more features.
An identifier is a name used to identify a variable, function, class, module, or other object.
A variable in Python is defined through assignment.
The basic data types used in Python are-
1.Number
a)Integer Number
b)Long Integer Number
c)Floating Point Number
d)Complex Number
2. None
3. Sequence
a) Strings
b) Tuples
c) List
4. Sets
5. Mappings
a) Dictionary
A mutable variable is one whose value may change in place, whereas in an immutable variable change of
value will not happen in place.
A hash sign (#) that is not inside a string literal begins a single line comment.
Multiline comments start from ###.
Python provides the following operators – Arithmetic, Relational, Logical, Assignment and other special
operators
Arithmetic operators are used for various mathematical calculations. They include the following :
Operator Description Example
+ Addition - Adds values on either side of the operator a=10, b=20, a + b will give 30
- Subtraction - Subtracts right hand operand from left hand operand a=10, b=20, a - b will give -10
* Multiplication - Multiplies values on either side of the operator a=10, b=20, a * b will give 200
/ Division - Divides left hand operand by right hand operand a=10, b=20, b / a will give 2
Modulus - Divides left hand operand by right hand operand and returns
% a=10, b=20, b % a will give 0
the remainder
a=10, b=20, a**b will give 10 to the
** Exponent - Performs exponential (power) calculation on operators
power 20
Floor Division - The division of operands where the result is the 9//2 is equal to 4 and 9.0//2.0 is equal to
//
quotient in which the digits after the decimal point are removed. 4.0
Relational Operator compares the value of any two operands and produce a result TRUE or FALSE
Operator Description Example
Checks if the value of two operands is equal or not, if yes it returns
== a=10, b=20, a == b) is not true.
true.
Checks if the value of two operands is equal or not, if values are not
!= a=10, b=20, (a != b) is true.
equal then condition becomes true.
Checks if the value of two operands is equal or not, if values are not a=10, b=20, (a <> b) is true. This is
<>
equal then condition becomes true. similar to != operator.
Checks if the value of left operand is greater than the value of right
> a=10, b=20, (a > b) is not true.
operand, if yes then condition becomes true.
Checks if the value of left operand is less than the value of right
< a=10, b=20, (a < b) is true.
operand.
Checks if the value of left operand is greater than or equal to the value
>= (a >= b) is not true.
of right operand,
Checks if the value of left operand is less than or equal to the value of
<= (a <= b) is true.
right operand, if yes then condition becomes true.
Logical operators connect two relational expressions and produce a truth value.
Operator Description Example
And If both the operands are true then the condition becomes true. a=10, b=20, (a and b) is true.
If any of the two operands are non zero then the condition
Or a=10, b=20, (a or b) is true.
becomes true.
Use to reverses the logical state of its operand. If a condition is
Not a=10, b=20, not(a and b) is false.
true then Logical NOT operator will make false.