Continuous Assessment 1 – Digital Literacy
Notes
PYTHON
Data Types in Python-
DATA
TYPES
IN
STRING Anything in double quotes
A-Z
a-z
NUMBERS
Integers Whole Numbers
Signed (+)
Unsigned (-)
Float Decimals
NONE
Operators-
Definition- Operators are symbols used to do
arithmetic and logical operations on the operands and
provide a meaningful result
Types of Operators-
1) Arithmetic Operator:
Definition – The type of operator used to perform
basic mathematical calculation
A] Unary Operators: -
Definition- The arithmetic operator that can operate
only one operand.
E.g.} a= (-100)
print a
-100
B] Binary Operators: -
Definition- The arithmetic operator that can operate 2
or more operands.
Types of Binary Operators-
[i] Addition (+)
Use – To obtain the sum of the values.
E.g. – 13+3.5=16.5
[ii] Subtraction (-)
Use – To obtain the difference of the values.
E.g. – 13-3.5=19.5
[iii]Multiplication (*)
Use – To obtain the product of the values.
E.g. – 13*3=39
[iv]Division (/)
Use – To divide values and give an output in decimal
form.
E.g. – 5/2=2.5
[v]Floor Division (//)
Use – To divide values and give an output in integer
form
E.g. – 5/2=2
[vi]Remainder (%)
Use – To divide values and find the remainder
E.g. – 10%6=4
[vii]Exponents (**)
Use – To calculate power of values
E.g. – 2**3=8
2) String Operator:
Definition – The type of operator used to join and
replicate string values
A] Concatenation Operator [+] : -
Definition- The string operator that can join 2 or
more values.
E.g. 1} “a” + “b”
print “a” + “b”
ab
E.g. 2} “2” + “3”
print “2” + “3”
23
B] Replication Operator [*] : -
Definition- The string operator that can replicate
values.
E.g.} “a”= CNS
print (“a”*3)
CNSCNSCNS
3) Assignment Operator (=):
Definition – The type of operator used to assign a
value to a variable.
E.g.} x = 12
y=2
print (x*y)
24
4) Relational Operators:
Definition – The type of operator used to compare
operands.
Note – In Python result provided is in Boolean
expression type i.e., true or false
Operator Symbol
Less Than <
Less Than or Equal to <=
Equal to ==
Greater Than >
Greater Than or Equal >=
to
Not Equal to !=
Expression Result
y<x True
y<=x True
x==x True
y>x False
y>=x False
y!=x True
x=12 y=2
5) Precedence Operators:
Definition – The type of operator used to evaluate
according to an order from highest to lowest priority.
Bracket
Open
Division E.g.} 10/ (3+2)
Multiplication 10/5 } Solve bracket
2 } Find result
Addition
Subtraction
6) Logical/Boolean Operators:
Definition – The type of operator used to evaluate the 1
of the 2 states.
AND & OR
Practical
Theory
E.g. 1} p=int(input(“ ”)) Have to
t=int(input(“ ”)) pass in
if p>35 AND T>35 both
print (“pass”) criteria
else or it is a
print (“fail”) failure
Control Statements-
Definition- Control statements help users specify the
order of execution of the instructions present in a
program.
TYPE OF
STATEMENTS IN
Sequential Repetitive
Conditional
Control Structures that govern flow of
execution in programs-
1) Sequential Structures:
Definition – The statements in a program are
executed in a sequential manner, i.e., one after
another with no possibility of branching off to
another action are known as Sequential statements.
E.g. 1} l=int(input(“Enter the length of the rectangle.”))
b=int(input(“Enter the breadth of the rectangle.”))
ar=l*b
print (“The area of the rectangle is:”, ar”)
2) Conditional Structures:
Definition – Definition- Conditional statements are
the type of statements that check the condition and
execute statements accordingly.
E.g.}
Condition Plan of Action
If age>=18 Then you can apply for driver’s license.
If age<=18 Then you can’t apply for driver’s license.
3) Iterative Structures:
Definition – Iterative statements (looping statements)
enable execution of a set of statements to be repeated
till the condition is true.
Conditional Statements-
Definition- Conditional statements are the type of
statements that check the condition and execute
statements accordingly.
Types of Conditional Statements-
1) The if statement:
Definition – The if statements are used to evaluate
one condition.
Syntax} if <condition>:
statement 1
statement 2
2) The if…. else statement:
Definition – The if... else statements are used when
either of the 2 different actions is to be performed
depending upon the result of the conditional
expression.
Syntax} if <condition>:
statement set 1
else:
statement set 2
3) The if…. elif…. else statement:
Definition – The if...elif… else statements are used
when you need to work with multiple conditions and
to provide a compact way to perform multiple tests
on one condition.
Syntax} if <condition>:
statement set 1
elif <condition 2>:
statement set 2
elif <condition 3>: