Python For Half Yearly
Python For Half Yearly
What is an Algorithm?
step-by-step method to solve the identified problem is called algorithm
Example: Write the steps to make greeting card
What is a flowchart?
A flowchart is the graphical or pictorial representation of an algorithm with the help of different
symbols, shapes and arrows in order to demonstrate a process or a program.
What is a program?
A computer program is a collection of instructions that perform a specific task when executed by a
computer.
Applications of Python
• Web and Internet Development
• Business applications
• Games and 3D Graphics
• Database Access
• Software development
• Desktop GUI Applications
Python shell can be used in two ways, viz., interactive mode and script mode.
• Interactive Mode, as the name suggests, allows us to interact with OS;
• Script mode lets us create and edit Python source file.
Python Statement: Instructions written in the source code for execution are called statements.
Python Comments: It is just a piece of text to let someone know what you have done in a program or
what is being done in a block of code. Comments can be single line using # symbol and can be
multiline using “”” or ‘ ‘ ‘
Variables: A variable is a named location used to store data in the memory. Example: x=5
DataTypes:
• int: It is Python numeric type that accepts negative, positive and zero. Example: 7, 4, -2, 0.
(Decimal values are not assigned)
• float: It is Python numeric type that accepts decimal value. Example: 7.89, 98.3
• boolean: This data type either accepts True or False.
• sting: This data type involves collection of letters. Example: “APS Meerut”, “class IX”
• lists: Lists are used to store multiple items in a single variable. It is ordered and changeable.
Example: marks=[67, 78, 34, 56, 69]
• tuples: Tuples are used to store multiple items in a single variable. It is ordered and
unchangeable. Marks=(67, 78, 34, 56, 69)
Python Operators:
Operators are special symbols that perform a specific operation on operands.
Following are the types of operators:
• Arithmetic Operators: These operators are used to perform arithmetic calculations.
Following are the types of arithmetic operators:
Operator Meaning Expression Result
+ Addition 10 + 20 30
- Subtraction 30 - 10 20
* Multiplication 30 * 100 3000
/ Division 5/2 2.5
// Integer Division 5 // 2 2
% Remainder 7%2 1
** Exponents 3 ** 2 9
• Assignment Operators: These operators are used to assign a value to a variable. Following
are the assignment operators: (if X= 5)
Operator Meaning Expression Updated value of X
= Equal to X= 5 5
+= Addition assignment X += 5 10
-= Subtraction assignment X -= 2 3
*= Multiplication assignment X *= 6 30
/= Division assignment X /= 2 2.5
//= Integer Division assignment X //= 2 2
%= Remainder X %= 2 1
**= Exponents X **= 2 25
• Comparison Operators: These operators are used to compare the values. Following are the
comparison operators available in Python
Operator Meaning Expression Result
> Greater than 20 > 15 True
>= Greater than and equal to 20 >= 45 False
< Lesser than 16 < 12 False
<= Lesser than and equal to 16 <= 16 True
== Equal to or checking equivalence 5 == 5 True
!= Not equal to 5 != 5 False
• Logical Operator: Logical operators are generally used for combining two or more relational
statements.
Operator Meaning Description
and Logical and Returns True only when all the statements are True
or Logical or Returns False only when all the statements are False
not Logical not Reverses the result of the statement
Truth Table:
A B A and B A B A or B
T T T T T T
T F F T F T
F T F F T T
F F F F F F
A not A
T F
F T
print() Command in Python: It is used to obtain the output on the screen. Following are some
examples:
Print Statement Output
print(“Hello”) Hello
print(67 + 10) 77
print(“67 + 10”) 67 + 10
print(“67” + “10”) 6710
print(“My Percentage is”, 98) My Percentage is 98
print(“Hello” + “ World”) Hello World
print(9 + 4 * 2) 17
Python Lists: The list is a sequence data type which is used to store the collection of data. It is
ordered and changeable. Example: s_marks= [56, 78, 89, 60, 70]
Statement Output
s_marks[0] 56
s_marks[2] 89
s_marks[-1] 70
Python Tuples: The tuple is a sequence data type which is used to store the collection of data. It is
ordered and unchangeable. Example: s_marks= (56, 78, 89, 60, 70)