Python Notes (Class 10)
1. Algorithms and Flowcharts
Algorithm
An algorithm is a step-by-step procedure used to solve a problem.
Example: Algorithm to make tea
1. Boil water.
2. Add tea leaves and sugar.
3. Add milk.
4. Boil for some time.
5. Pour into a cup and serve.
Characteristics of an Algorithm
• Clear and easy steps
• Finite number of steps
• Logical order
• Produces output
Flowchart
A flowchart is a graphical representation of an algorithm using symbols.
Common Flowchart Symbols
Symbol Meaning
Oval Start/End
Parallelogram Input/Output
Rectangle Process
Diamond Decision
Arrow Flow of control
Flowcharts help us visualize the steps of a program.
2. Introduction to Python
What is a Program?
A program is a set of instructions written in a programming language that tells a computer what to do.
What is Python?
Python is a high-level programming language used for:
• Web development
• Data analysis
• Artificial Intelligence
• Game development
• Software development
Why Python is Popular
• Easy to learn
• Simple syntax
• Large libraries
• Used in AI and Data Science
Applications of Python
Python is used in:
• Web and internet development
• Business applications
• Games and graphics
• Database applications
• Desktop software
3. Python Environment
Python IDE
Python provides an IDE called IDLE (Integrated Development Environment).
It allows you to:
• Write programs
• Run programs
• Debug code
Two Modes in Python
1. Interactive Mode
• Commands are executed immediately.
• Used for testing small code.
Example
>>> 3 + 10
13
>>> print("Hello")
Hello
2. Script Mode
• Code is written in a file and saved with .py extension.
Example
print("Hello World")
4. Python Statements and Comments
Statement
A statement is an instruction written in a program.
Example
a = 10
Comments
Comments are used to explain code and are ignored by Python.
Example
# This is a comment
print("Hello")
5. Keywords and Identifiers
Keywords
Keywords are reserved words used by Python.
Examples:
if
else
while
for
True
False
None
Identifiers
Identifiers are names given to variables, functions, or objects.
Example
age = 15
name = "Rahul"
Rules:
• Must start with a letter or underscore
• Cannot use keywords
• Cannot contain spaces
• Python is case-sensitive
Example
Age ≠ age
6. Variables
Variable
A variable is a container used to store data.
Example
x = 10
name = "Ravi"
Here:
• x stores number 10
• name stores text "Ravi"
7. Data Types in Python
1. Integer (int)
Whole numbers.
Example
x = 10
2. Float
Decimal numbers.
Example
x = 10.5
3. String
Text values inside quotes.
Example
name = "Rahul"
4. Boolean
Logical values.
True
False
5. List
Collection of elements inside square brackets.
Example
numbers = [1,2,3,4]
6. Tuple
Collection of elements inside parentheses.
Example
t = (1,2,3)
7. Dictionary
Stores data in key-value pairs.
Example
student = {"name":"Rahul", "age":15}
8. Python Operators
Arithmetic Operators
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
// Floor Division
% Modulus
** Power
Example
a = 10
b=5
print(a + b)
Output
15
Comparison Operators
Operator Meaning
> Greater than
< Less than
== Equal
!= Not equal
>= Greater or equal
<= Less or equal
Example
5>3
Output
True
Logical Operators
Operator Meaning
and Both conditions true
or One condition true
not Reverse condition
Example
True and False
Output
False
9. Input and Output
Output Function
print() displays output on screen.
Example
print("Hello")
Input Function
input() takes input from the user.
Example
name = input("Enter your name:")
print(name)
10. Type Conversion
Type Conversion
Changing one data type to another.
Two types:
1. Implicit Conversion
Python automatically converts data type.
Example
a = 10
b = 2.5
print(a + b)
Output → 12.5
2. Explicit Conversion
Programmer converts data type manually.
Example
a = "10"
b = int(a)
print(b + 5)
Output → 15
11. Lists
Creating a List
numbers = [1,2,3,4]
Accessing List Elements
numbers[0]
Output
Adding Elements
[Link](5)
Removing Elements
[Link](3)
12. Tuples
A tuple is similar to a list but cannot be changed (immutable).
Example
t = (10,20,30)
13. Control Statements
If Statement
age = 18
if age >= 18:
print("Eligible to vote")
If-Else
num = 10
if num % 2 == 0:
print("Even")
else:
print("Odd")
14. Loops
For Loop
Used when number of repetitions is known.
Example
for i in range(1,6):
print(i)
Output
1
2
3
4
5
While Loop
Used when condition is required.
Example
i=1
while i <= 5:
print(i)
i=i+1
15. Python Tools for AI
Anaconda
Anaconda is a Python distribution used for data science and machine learning.
It helps to:
• Manage packages
• Create environments
• Run data science tools
Jupyter Notebook
Jupyter Notebook is a tool used to write code, notes, and visualizations in one document.
Features:
• Interactive coding
• Data visualization
• Easy debugging