Python Basic
Python Basic
Programming
1
Syllabus
• Basic Python 5. Functions
1. Introduction 6. File Handling
2. Variables, Expressions & 7. Modules
Statements.
3. List, Dictionary and Tuples
4. Conditionals and Loops
2
Why Python?
3
Python Definition
4
Compiler & Interpreter
• Compiler • Interpreter
• A Compiler is a complex piece of • A interpreter is software that is
software whose work is to convert used to convert source code to
Source code to machine machine understandable code but it
understandable code or binary code does it in line by line.
in one Go.
5
6
Basic Data Types in Python
7
Variables in Python
• A variable is a name that is attached to a value which can be changed and is
used later in code.
• Examples:- A value of variable can be
Variable name changed
a =10
Variable name
Name = “Saurav”
List = [24,23, “Tushar”]
Variable name
8
9
10
11
12
13
14
15
16
What is Variable?
- A variable is a Label given to some object.
- Do not take extra memory.
Ex- age= 24
17
What are Operators?
An operator is a symbol that will perform mathematical operations on variables or on values. Operators
operate on operands values) and return a result.
Arithmetic Operators
Relational Operators
Assignment Operators
Logical Operators
Membership Operators
Identity Operators
18
1. Arithmetic Operators: 2. Comparison Operators:
Addition (+): Adds two values. Equal to (==): Returns True if the values on
both sides are equal.
Subtraction (-): Subtracts the right operand
from the left operand. Not equal to (!=): Returns True if the values
on both sides are not equal.
Multiplication (*): Multiplies two values.
Greater than (>): Returns True if the left
Division (/): Divides the left operand by the operand is greater than the right operand.
right operand.
Less than (<): Returns True if the left
Floor Division (//): Returns the largest operand is less than the right operand.
integer less than or equal to the division
result. Greater than or equal to (>=): Returns True if
the left operand is greater than or equal to the
Modulus (%): Returns the remainder of the right operand.
division.
Less than or equal to (<=): Returns True if
Exponentiation (**): Raises the left operand the left operand is less than or equal to the
to the power of the right operand. right operand. 19
3. Logical Operators: Multiplication assignment (*=): Multiplies the
Logical AND (and): Returns True if both left operand by the right operand and assigns
operands are True. the result to the left operand.
Logical OR (or): Returns True if at least one Division assignment (/=): Divides the left
operand is True. operand by the right operand and assigns the
result to the left operand.
Logical NOT (not): Returns True if the
operand is False and vice versa.
4. Assignment Operators:
Addition assignment (+=): Adds the right
operand to the left operand and assigns the
result to the left operand.
20
4. Assignment Operators: 5. Identity Operators:
Addition assignment (+=): Adds the right operand Identity (is): Returns True if both operands refer to
to the left operand and assigns the result to the left the same object.
operand.
Identity (is not): Returns True if both operands do
Subtraction assignment (-=): Subtracts the right not refer to the same object.
operand from the left operand and assigns the
result to the left operand. 6. Membership (in): Returns True if the left
operand is a member of the right operand.
Multiplication assignment (*=): Multiplies the left
operand by the right operand and assigns the result Membership (not in): Returns True if the left
to the left operand. operand is not a member of the right operand.
21