0% found this document useful (0 votes)
7 views9 pages

CH 1-Modes in Python

The document provides an introduction to Python, highlighting its features as a high-level, open-source, and interpreted programming language. It discusses two execution modes: Interactive Mode, which allows for immediate command execution but lacks saving capabilities, and Script Mode, which enables the creation and saving of Python files for future use. Additionally, it covers basic input and output functions, escape characters, and the use of comments in Python code.

Uploaded by

15988
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)
7 views9 pages

CH 1-Modes in Python

The document provides an introduction to Python, highlighting its features as a high-level, open-source, and interpreted programming language. It discusses two execution modes: Interactive Mode, which allows for immediate command execution but lacks saving capabilities, and Script Mode, which enables the creation and saving of Python files for future use. Additionally, it covers basic input and output functions, escape characters, and the use of comments in Python code.

Uploaded by

15988
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/ 9

THE ASIAN SCHOOL

KINGDOM OF BAHRAIN

GRADE:10 SUBJECT: COMPUTER SCIENCE

Introduction to Python:

Python is a general-purpose Object-Oriented Programming language, High-level language


Developed in late 1980 by Guido van Rossum at National Research Institute for Mathematics and
Computer Science in the Netherlands. It is a Open Source Scripting language and is Case-sensitive
language.

Features of Python

• Python is a high level language. It is a free and open source language.

• It is an interpreted language, as Python programs are executed by an interpreter.

• Python programs are easy to understand as they have a clearly defined syntax and

relatively simple structure.

• Python is case-sensitive. For example, NUMBER and number are not same in Python.

• Python is portable and platform independent, means it can run on various operating

systems and hardware platforms.

• Python has a rich library of predefined functions.

• Python is also helpful in web development. Many popular web services and

applications are built using Python.

• Python uses indentation for blocks and nested blocks

There are two ways to use the Python interpreter:

a) Interactive mode b) Script mode


EXECUTION MODES OF PYTHON

1.1 Mode 1 - Interactive Mode

Interactive Mode:
❖ Allow us to interact with the operating System.
❖ Commands are executed line by line and give output at the same time when the enter key is
pressed.
❖ Commands are typed in front of Python commands prompt >>>
❖ IDLE -integrated development and learning environment.

Problems with the interactive mode of Python


❖ We cannot save the command given by the user.
❖ There is no code created or saved that can be used for user reference.
❖ The output is sandwiched between the commands and creates confusion when longer
programs are designed.
Advantages of Interactive Mode

The interactive mode is great for testing out commands and getting immediate feedback.
It can also be used to quickly execute commands on a remote server.

Disadvantages of interactive mode

1.The interactive mode is not suitable for large programs.


2.The interactive mode doesn’t save the statements. Once we make a program it is for that time
itself, we cannot use it in the future. In order to use it in the future, we need to retype all the
statements.
3.Editing the code written in interactive mode is a tedious task. We need to revisit all our
previous commands and if still, we could not edit we need to type everything again.

1.2 Mode 2 - Script Mode

a. Script Mode that enable us to create and edit python source file.
b. Files in python are saved with extension .py
c. Here File is created and save for future reference.
d. Code is written on the editor like Notepad.

Steps to open a python file in Script Mode


1. Open Python Shell
2. Click on ‘File’ option on the left menu.
3. An untitled python file opens up to type the code into it.
4. Type the code and save the file with a proper file name.

DIFFERENCE BETWEEN INTERACTIVE AND SCRIPT MODEDifference between


Iteractive mode a Script m

Interactive Mode Script Mode

It is a way of executing a Python In the script mode, the Python program is written in a
program in which statements are file. Python interpreter reads the file and then
written in command prompt and result executes it and provides the desired result. The
is obtained on the same. program is compiled in the command prompt,

The interactive mode is more suitable Script mode is more suitable for writing long
for writing very short programs. programs.

Editing of code can be done but it is a


Editing of code can be easily done in script mode.
tedious task.

We get output for every single line of


code in interactive mode i.e. result is In script mode entire program is first compiled and
obtained after execution of each line of then executed.
code.

Code cannot be saved and used in the


Code can be saved and can be used in the future.
future.

It is more preferred by experts than the beginners to


It is more preferred by beginners.
use script mode.
1.3 SIMPLE INPUT AND OUTPUT

1.3.1 Input using the function input()

Built-in function input () can be used to get the input from the user interactively as follows:

• Input() always returns value of the string data type hence below error occurs.

• Even though the age entered is a number, input() returns it as a string value.

• Reading numbers(int or float) using input()


• Possible errors while reading numbers (int or float) using input()
1.3.2 OUTPUT USING THE FUNCTION PRINT()

Syntax: print(object(s), sep, end)


• Object(s): It can be any python object(s) like string, list, tuple, etc. But before printing all
objects get converted into strings.

• sep: It is an optional parameter used to define the separation among different objects to be
printed. By default an empty string(“”) is used as a separator.

• end: It is an optional parameter used to set the string that is to be printed at the end. The
default value for this is set as line feed(“\n”).

➢ It auto-converts the items to string.

➢ The return type of the print function is “None”


1.3.3. PYTHON ESCAPE CHARACTERS
Video Links to understand how carriage return and backspace (\r,\b) works.
[ Few python versions/systems donot support them]

• What is \r in python?

• What is \b in python?
1.4 USE OF COMMENTS
Comments can be used to :

➢ Explain Python code.


➢ Make the code more readable.
➢ prevent execution when testing code.

Types :

1. Single Line Comment

2. Multiline Comment

3. Inline Comment

http://python.mykvs.in/uploads/tutorials/XIComp.Sc.58.pdf

https://youtu.be/PQO-DyK3R2M?feature=shared

You might also like