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

Introduction to Python

The document is an educational resource for Class 9 students at Indus Public School, Rohtak, focusing on an introduction to Python programming. It covers Python modes (Interactive, Script, and IDE), basic functions like print() and input(), and provides installation and usage instructions. The content aims to equip students with foundational knowledge for writing and executing Python code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Introduction to Python

The document is an educational resource for Class 9 students at Indus Public School, Rohtak, focusing on an introduction to Python programming. It covers Python modes (Interactive, Script, and IDE), basic functions like print() and input(), and provides installation and usage instructions. The content aims to equip students with foundational knowledge for writing and executing Python code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Indus Public School, Rohtak

(CBSEAff. No. 530439) Delhi Road, Rohtak-124001 (Haryana)

Class -9

Unit -5

Ch-2: Introduction to python

1. Python Modes

Mode How to Start Best for


Interactive
python in Command Prompt/Terminal Small tests or quick calculations
Mode
Script Mode Save code as .py and run using python Writing and running complete
<filename.py> programs
IDE Open IDLE or any Python IDE (VS Writing large programs with
(IDLE/Other) Code, PyCharm, etc.) features like debugging

A. Short Answer Questions

Q1. What is Python?


Answer:
Python is a high-level, interpreted programming language that is easy to learn and use. It is
widely used in AI, web development, automation, and data science.

Q2. Who developed Python and when?


Answer:
Python was developed by Guido van Rossum in the late 1980s and released in 1991.

Q3. Name any two features of Python.


Answer:
1. Easy to read and write
2. Free and open-source

Q4. What is the use of the print() function in Python?


Answer:
The print() function is used to display output on the screen.

Q5.What is Input() function?

Ans : input() function is used to take input from the user. It allows the user to type something on the
console, and the program stores that input as a string. The input() function always returns the input
as a string (even if you enter numbers, they are treated as strings unless converted).

How input() Works:

1. Displays the prompt (if any) on the screen.


2. Waits for the user to type something and press Enter.
3. Returns the entered data as a string.
Practical Knowledge (just read it carefully or you can paste it in notebook)

1. Installing Python:

To start programming in Python, you need to have Python installed on your computer.

Steps to Install Python:

1. Go to the official Python website: https://www.python.org/downloads/


2. Download the latest version (Python 3.x).
3. Run the installer and make sure to check the box that says “Add Python to PATH”
during installation.

2. Starting Python and Running Code

Python can be run in three different modes:

A. Interactive Mode (Python Shell)

In Interactive Mode, you can write and execute Python code directly.

How to Use Python in Interactive Mode:

1. Open Python Shell:


After installing Python, open the Command Prompt (Windows) or Terminal
(Mac/Linux), then type python and press Enter.
2. Start Writing Python Code:
You will see a prompt >>> which means the Python interpreter is ready to accept
commands.
3. Write and Execute Code:
You can now enter Python code line by line. For example:

python
CopyEdit
>>> print("Hello, World!")
Hello, World!

This code will immediately display the output in the same window.

Advantages of Interactive Mode:


 Great for testing small code snippets.
 No need to save files to execute.

B. Script Mode (Using a Text Editor or IDE)

In Script Mode, you can write a complete Python program in a text file and save it with a .py
extension, then run it as a script.

How to Use Python in Script Mode:

1. Write Your Code in a Text Editor:


o Open any text editor (like Notepad, VS Code, or IDLE).
o Write your Python code. For example:

python
CopyEdit
print("Hello, World!")

2. Save Your Code:


o Save the file with a .py extension. For example: hello_world.py.
3. Run the Python Script:
o Open the Command Prompt or Terminal.
o Navigate to the directory where the file is saved.
o Type python hello_world.py and press Enter.

Advantages of Script Mode:

 Suitable for writing larger programs.


 Can save your work and reuse it later.

C. IDE (Integrated Development Environment)

IDLE and other IDEs (like PyCharm, VS Code, or Jupyter Notebook) are environments that
provide tools like syntax highlighting, auto-completion, debugging, etc., making it easier to write
Python code.

Using IDLE (Python's default IDE):

1. Open IDLE:
o After installing Python, you can open IDLE (comes bundled with Python).
o It has an interactive shell, but you can also write scripts by selecting File > New
File.
2. Write Your Code:
You can write your Python program in the opened file, just like in Script Mode.
3. Run the Program:
To run the program, click Run > Run Module or press F5.

Advantages of Using an IDE:

 Easy debugging tools.


 Helps in writing larger, more complex projects.

Provides features like syntax checking and code suggestion

You might also like