0% found this document useful (0 votes)
9 views

Python For Half Yearly

Uploaded by

bigbenyt0098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python For Half Yearly

Uploaded by

bigbenyt0098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Unit-4 Python (Notes Class IX)

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.

What is a programming language?


a programming language is a vocabulary and set of grammatical rules for instructing a computer to
perform specific tasks. Eg: Python

Why Python for AI?


• Easy to learn, read and maintain
• A broad standard library to solve problems
• Interactive testing and debugging
• Portability and compatibility
• Extendable
• Support for databases and large programs

Applications of Python
• Web and Internet Development
• Business applications
• Games and 3D Graphics
• Database Access
• Software development
• Desktop GUI Applications

IDLE: Integrated Development Learning Environment


IDLE (GUI integrated) is the standard, most popular Python development environment. IDLE is an
acronym of Integrated Development Environment. It lets one edit, run, browse and debug Python
Programs from a single interface. This environment makes it easy to write programs.

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

input() command in Python: It is used to accept input from the user.


Syntax Meaning
S_name= input(“Enter Your Name”) To accept string value from the user
marks= int(input(“Enter your Marks”)) To accept integer value from the user
marks= float(input(“Enter your Marks”)) To accept decimal value from the user
Type Conversion:
The process of converting the value of one data type (integer, string, float, etc.) to another data type
is called type conversion. Python has two types of type conversion.
1. Implicit Type Conversion: In this, Python automatically converts one data type to another data
type.
2. Explicit Type Conversion: In this type, user converts the value from one data type to another.
Functions used are: int(), float(), bool(), str().

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)

You might also like