MDH INTERNATIONAL SCHOOL
SECTOR-6, DWARKA
CLASS-9
PYTHON
_____________________________________________
Introduction to Python
Python is a high-level, interpreted, and general-purpose programming language. It is widely used for
web development, data analysis, artificial intelligence, scientific computing, automation, and more.
Python emphasizes readability, which makes it a great choice for beginners as well as professionals.
Features of Python
• Simple and easy to learn
• Open-source and free to use
• Interpreted language
• High-level language
• Extensive standard library
• Portable and cross-platform
• Supports multiple programming paradigms (procedural, object-oriented, functional)
Importance of Python
Python is important because it is versatile, beginner-friendly, and has a huge community support. It
is widely used in emerging fields such as data science, machine learning, artificial intelligence, and
cloud computing. Many large companies like Google, Netflix, and NASA use Python for various
applications.
Python Comments
Comments in Python are used to explain code and make it more readable. They are ignored by the
Python interpreter.
1. Single-line comment: Use the '#' symbol.
Example:
# This is a single-line comment
2. Multi-line comment: Use triple quotes (''' or """) to span multiple lines.
Example:
'''
This is a
multi-line comment
'''
Python print() Function
The print() function is used to display output to the console. It can print strings, numbers,
variables, and even formatted text.
Example 1:
print('Hello, World!')
Output:
Hello, World!
Example 2:
name = 'Alice'
print('Hello', name)
Output:
Hello Alice
Python input() Function
The input() function is used to take input from the user. It always returns the input as a string, so
type conversion may be needed.
Example 1 – Taking a name as input
name = input("Enter your name: ")
print("Hello", name)
Example 2 – Taking numbers and converting to integer
age = int(input("Enter your age: "))
print("You will be", age + 1, "next year.")
Errors in Python
Errors in Python occur when the program cannot execute due to invalid code. There are mainly
two types of errors:
1.Syntax Errors – Occur when the rules of Python syntax are violated.
if 5 > 2:
print('Five is greater than two')
2.Runtime Errors – Occur during execution due to invalid operations.
Example:
x = 10/0 # Division by zero
3.Logical Errors – Occur when the program runs without crashing but produces
incorrect results due to wrong logic or reasoning.
Example:
length = 5
width = 3
area = length + width # Wrong formula (should be multiplication)